package sample.controller;

import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

import com.jcraft.jsch.SftpException;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.input.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Paint;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.util.Callback;

import javafx.util.Duration;
import org.controlsfx.control.CheckTreeView;
import sample.analysis.util.NmonUtil;
import sample.model.*;
import sample.util.*;
import sample.web.WebApi;

import java.io.*;
import java.net.URI;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import static sample.util.SSHUtils.execCommandByJSch;

public class MyController {
//    public static Logger logger = LoggerFactory.getLogger(Main.class);
//    TextAreaAppender myTextAreaAppender = new TextAreaAppender();


    public static Properties properties = new Properties();
    private ServerInfo serverInfo;//服务器信息对象
    //存放服务器session连接
    private HashMap<String, Session> serverSessionMap = new HashMap<String, Session>();
    //存放tableview 数据
    ObservableList<ServerConfigurationModel> dataList = FXCollections.observableArrayList();
    //存放压测记录的 tableview 数据
    public static ObservableList<NmonMonitorListModel> monitorHistoryDataList = FXCollections.observableArrayList();
    //存放监控片段的 tableview 数据
    ObservableList<MonitorFragmentModel> monitorFragmentDataList = FXCollections.observableArrayList();
    //存放自定义表 tableview 数据
    ObservableList<ZDYdataModel> ZDYDataList = FXCollections.observableArrayList();


    //数据库连接
    public static H2dbCRUDUtil h2dbCRUDUtil = null;

    //获取基础信息
    getServiceBaseInfoService gsbs = new getServiceBaseInfoService();
    //获取监控片段
    getMonitorConfigurationService gmcs = new getMonitorConfigurationService();
    //自定义任务执行
    getZDYdataService gzds = new getZDYdataService();

    disConnectSessionScheduledService dss = new disConnectSessionScheduledService();
    connectSessionScheduledService css = new connectSessionScheduledService();

    //上传nmon文件
    upLoadNmonService myupLoadNmonService = new upLoadNmonService();
    //上传自定义文件
    ZDYupLoadFileService zlfs = new ZDYupLoadFileService();
    //开始监控
    startJmonitorScheduledService sjss = new startJmonitorScheduledService();
    //停止监控
    stopJmonitorScheduledService stjss = new stopJmonitorScheduledService();
    //删除监控
    deleteMonitorNmonFileService dmnfs = new deleteMonitorNmonFileService();
    //下载监控文件
    downloadMonitorNmonFileService dlmnfs = new downloadMonitorNmonFileService();
    //下载自定义文件
    ZDYdownloadFileService zdlfs = new ZDYdownloadFileService();
    //倒计时
    delaytimeService dts = new delaytimeService();
    private Boolean delayFlag = false;
    //鼠标点击表格的坐标
    private String[] ActultablePosition = new String[]{"0","0"};
    //解析nmon文件
    analysisNmonResultService anrs = new analysisNmonResultService();

    Button progressFromCancel = new Button();

    @FXML
    private VBox UI_MAIN;
    @FXML
    private TabPane TabPane_UI;

    private ProgressFrom pf ;


    @FXML
    private CheckTreeView<String> CheckTreeView_hostIP;

    @FXML
    private TextArea logArea;
    private PrintStream ps;


    @FXML
    private void Controller() {
        System.out.println("无参构造");
    }

    @FXML
    public void onbuttonclick(ActionEvent event) {
        progressLabel.setText("test");
    }

    @FXML
    private Label progressLabel;

    @FXML
    private MenuItem selectServerInfoFile;


    //tableview 相关属性
    @FXML
    private TableView<ServerConfigurationModel> tableview;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_serverName;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_hostIP;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_CPU;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_MEM;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_diskSpace;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_javaVersion;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_hostName;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_systemType;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_systemVersion;

    @FXML
    private TableColumn<ServerConfigurationModel, String> C_serverDate;


    //压测日志记录表相关配置
    @FXML
    private TableView<NmonMonitorListModel> tableview_MonitorHistoryList;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_id;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_startTime;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_frequency;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_duration;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_nmonName;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_PS;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_isDownload;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_isAnalysis;

    @FXML
    private TableColumn<NmonMonitorListModel, String> C_toLink;


    @FXML
    private Button B_AnalyseNmonResult;

    //选择服务器信息文件事件
    @FXML
    void selectServerInfoFileOnAction(ActionEvent event) {
        System.out.println("选择应用服务器");
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialDirectory(new File(new File("").getAbsoluteFile()+File.separator+"serverInfo"));
        fileChooser.setTitle("选择服务信息文件");
        fileChooser.getExtensionFilters().addAll(
                new FileChooser.ExtensionFilter("Text Files", "*.csv"),
                new FileChooser.ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif"),
                new FileChooser.ExtensionFilter("Audio Files", "*.wav", "*.mp3", "*.aac"),
                new FileChooser.ExtensionFilter("All Files", "*.*"));
        File selectedFile = fileChooser.showOpenDialog(UI_MAIN.getScene().getWindow());
        if (selectedFile != null) {
            String filepath = selectedFile.getAbsolutePath();
            //更新server展示
            DoServerInfo(filepath);
            //更新右边状态 服务器信息文件路径
            rightstatus.setText(filepath);
            System.out.println("选取文件路径为" + filepath);
        }
    }

    @FXML
    private Button button_getServerConfiguration;

    //获取服务器信息
    @FXML
    void getServerConfiguration(ActionEvent actionEvent) {
        pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
        pf.setStr("获取信息中...");
        pf.activateProgressBar();
        if (gsbs.getState().toString().contains("READY")) {
            gsbs.start();
        } else {
            gsbs.restart();
        }
    }

    @FXML
    void disconnect(ActionEvent event) {
        pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
       // System.out.println("serverSessionMap.size :"+serverSessionMap.size());
        pf.setStr("断开连接中...");

        //先断开连接
        if (leftstatus.getText().contains("已连接")) {
            pf.activateProgressBar();
            if (dss.getState().toString().contains("READY")) {
                dss.start();
            } else {
                dss.restart();
            }
        } else {
            logArea.appendText("已处于未连接状态...\r\n");
        }
    }

    @FXML
    private MenuItem MI_getConedtion;

    @FXML
    void getConnection(ActionEvent event) {
        pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
       // System.out.println("serverSessionMap.size :"+serverSessionMap.size());

        //设置等待动画文字提示
        pf.setStr("连接中...");

        css.setDelay(Duration.seconds(1));
        css.setMaximumFailureCount(5);
        //先断开连接
        if (leftstatus.getText().contains("已连接")) {
            //加载等待动画
            pf.activateProgressBar();
            if (dss.getState().toString().contains("READY")) {
                dss.start();
            } else {
                dss.restart();
            }
            if (css.getState().toString().contains("READY")) {
                css.start();
            } else {
                css.restart();
            }
        } else {
            serverSessionMap.clear();
            //加载等待动画
            pf.activateProgressBar();
            //获取连接
            if (css.getState().toString().contains("READY")) {
                css.start();
            } else {
                css.restart();
            }
        }
    }

    /**
     *
     * @param event
     * 1.判断是否存在连接 存在则先断开，不存在则直接连接
     */
    @FXML
    void reconnecting(ActionEvent event) {
        pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
        pf.setStr("重新连接中，请等待");
        pf.activateProgressBar();

        css.setMaximumFailureCount(1);
        dss.setMaximumFailureCount(1);
        //先判断是否存在连接
        if (leftstatus.getText().contains("已连接")) {//已连接状态

            if (dss.getState().toString().contains("READY")) {
                dss.start();
            } else {
                dss.restart();
            }

            if (css.getState().toString().contains("READY")) {
                css.start();
            } else {
                css.restart();
            }
        }else {//未连接状态
            if (css.getState().toString().contains("READY")) {
                css.start();
            } else {
                css.restart();
            }
        }
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    @FXML
    private TextField TF_setNmonPath;

    @FXML
    private TextField TF_frequency;

    @FXML
    private TextField TF_duration;

    @FXML
    private TextField TF_counts;

    @FXML
    private TextField TF_delayed_h;

    @FXML
    private TextField TF_delayed_min;

    @FXML
    private TextField TF_MonitoringNmonName;

    @FXML
    private TextField TF_downloadPath;//下载路径

    @FXML
    private TextField TF_downloadPath1;//下载文件归属文件夹

    @FXML
    private Button B_openDownloadPath;

    @FXML
    public  TextField TF_downloadFileName;

    @FXML
    private ProgressBar Bar_process;

    @FXML
    private Label L_processLabel;

    @FXML
    private Button B_startDownload;

    @FXML
    private Button B_startMonitor;

    @FXML
    private Button B_stopMonitor;

    @FXML
    private Button B_deleteMonitorNmonFile;

    @FXML
    private Button B_selectDownloadPath;

    @FXML
    private CheckBox CB_delay;

    @FXML
    private Label L_delayTime;

    @FXML
    private Label L_nodelay;

    @FXML
    private TextField TF_PS;
    
    //自定义页面相关
    @FXML
    private TextField TF_FileAbsolutePath;

    @FXML
    private TextField TF_ServiceAbsolutePath;

    @FXML
    private TextField TF_FileName;

    @FXML
    private TextField TF_MyCommand1;

    @FXML
    private CheckBox CB_MyCommand1;

    @FXML
    private Button B_ZDYexcute;

    @FXML
    private Button B_ZDY_upload;

    @FXML
    private Button B_ZDYdownload;

    @FXML
    private TextField TF_MyCommand2;

    @FXML
    private CheckBox CB_MyCommand2;

    @FXML
    private TextField TF_MyCommand3;

    @FXML
    private CheckBox CB_MyCommand3;

    @FXML
    private TextField TF_MyCommand4;

    @FXML
    private CheckBox CB_MyCommand4;

    @FXML
    private TableView<ZDYdataModel> tableview_ZDY;// TODO: 2021/8/6

    @FXML
    private TableColumn<ZDYdataModel, String> C_ServerName_ZDY;

    @FXML
    private TableColumn<ZDYdataModel, String> C_IP_ZDY;

    @FXML
    private TableColumn<ZDYdataModel, String> C_MyCommand1;

    @FXML
    private TableColumn<ZDYdataModel, String> C_MyCommand2;

    @FXML
    private TableColumn<ZDYdataModel, String> C_MyCommand3;

    @FXML
    private TableColumn<ZDYdataModel, String> C_MyCommand4;



    //自定义复制数据
    @FXML
    void onActionCopyZDYdata(ActionEvent event) {
        final Clipboard clipboard = Clipboard.getSystemClipboard();
        final ClipboardContent content = new ClipboardContent();
        String str = "服务器名称\tIP\t指令1结果\t指令2结果\t指令3结果\t指令4结果\r\n";
        for (int i = 0;i < ZDYDataList.size();i++){
            str = str+ZDYDataList.get(i).toString()+"\r\n";
        }
        content.putString(str);
        clipboard.setContent(content);
        System.out.println("监控记录 已复制到粘贴板");
    }

    //执行自定义命令
    @FXML
    void onActionZDYexcute(ActionEvent event) {

        //判断是否有删除文件命令
        if(TF_MyCommand1.getText().contains("rm -") || TF_MyCommand2.getText().contains("rm -") || TF_MyCommand3.getText().contains("rm -") || TF_MyCommand4.getText().contains("rm -")){
            if(properties.getProperty("isRM").toUpperCase()=="TRUE"){
                pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
                pf.setStr("获取信息中...");
                pf.activateProgressBar();
                if (gzds.getState().toString().contains("READY")) {
                    gzds.start();
                } else {
                    gzds.restart();
                }
            }else {
                System.out.println("不允许使用自定义模块 删除服务器文件，如需要，请配置");
            }
        }else {
            pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
            pf.setStr("获取信息中...");
            pf.activateProgressBar();
            if (gzds.getState().toString().contains("READY")) {
                gzds.start();
            } else {
                gzds.restart();
            }
        }

    }

    //上传自定义文件
    @FXML
    void onActionZDYupload(ActionEvent event) {
        Bar_process.setProgress(0);
        L_processLabel.setText("");
        //myupLoadNmonService.setDelay(Duration.seconds(1));
        //myupLoadNmonService.setPeriod(Duration.seconds(20));
        //System.out.println("开始上传: "+myupLoadNmonService.getState());
        if (zlfs.getState().toString().contains("READY")) {
            zlfs.start();
        } else {
            zlfs.restart();
        }
    }

    //自定义下载文件
    @FXML
    void onActionZDYdownload(ActionEvent event) {// TODO: 2021/8/7
        Bar_process.setProgress(0);
        L_processLabel.setText("");
        //System.out.println("开始下载: "+dlmnfs.getState());
        if (zdlfs.getState().toString().contains("READY")) {
            zdlfs.start();
        } else {
            zdlfs.restart();
        }

    }

    //

    @FXML
    void onActionAnalyseNmonResult(ActionEvent event) {
        //解析任务
//        test t  = new test();
//        t.setDelay(Duration.seconds(5));
//        t.setPeriod(Duration.seconds(1));
//        t.start();
//        NmonMonitorListModel nn = new NmonMonitorListModel("1","2","3","4","5","6");
//        monitorHistoryDataList.add(nn);
        //h2dbCRUDUtil.createSql("CREATE TABLE USER_INF(id INTEGER PRIMARY KEY, name VARCHAR(100), sex VARCHAR(2))");

//        h2dbCRUDUtil.insertOrUpdateSql("INSERT INTO USER_INF VALUES(1, 'tom', '男') ");
//        ResultSet resultSet = h2dbCRUDUtil.selectSql("select * from nmonMonitorList_table");
//
//        try{
//            while (resultSet.next()) {
//                System.out.println(
//                        resultSet.getInt("id") + ", " + resultSet.getString("startTime") + ", " + resultSet.getString("isAnalysis"));
//            }
//        } catch (Exception e){
//            e.printStackTrace();
//        }

        //h2dbCRUDUtil.createSql("truncate table nmonMonitorList_table");
//        sample.analysis.controller.MyController.ANALYSIS_UI_nmonFilePath = TF_downloadPath+File.separator+TF_downloadPath1;


        Bar_process.setProgress(0);
        L_processLabel.setText("");

        if (anrs.getState().toString().contains("READY")) {
            anrs.start();
        } else {
            anrs.restart();
        }

    }

    @FXML
    void onActionDeleteMonitoringNmonFile(ActionEvent event) {
        Bar_process.setProgress(0);
        L_processLabel.setText("");
        //System.out.println("删除服务器nmon文件");
        if (dmnfs.getState().toString().contains("READY")) {
            dmnfs.start();
        } else {
            dmnfs.restart();
        }
    }

    @FXML
    void onActionSelectDownloadPath(ActionEvent event) {
        //System.out.println("选择下载路径");
        DirectoryChooser directoryChooser=new DirectoryChooser();
        directoryChooser.setTitle("选择下载路径");
        File filepath = directoryChooser.showDialog(B_selectDownloadPath.getScene().getWindow());


        if (directoryChooser != null) {
            String path = filepath.getAbsolutePath();
            String path3;
            String path1;
            if(path.contains("/")){
                String path2[] = path.split("/");
                 path1 = path.split("/")[path2.length-1];
                 path3 = path.split(path1.toString())[0];
                System.out.println("path3"+path3);
                System.out.println("path1"+path1);
            }else {
                String path2[] = path.split("\\\\");
                path1 = path.split("\\\\")[path2.length-1];
                path3 = path.split(path1.toString())[0];
            }

            //更新右边状态 服务器信息文件路径
            TF_downloadPath.setText(path3);
            TF_downloadPath1.setText(path1);
            System.out.println("选择下载路径为" + filepath);
        }
    }

    @FXML
    void onActionStartDownload(ActionEvent event) {
        Bar_process.setProgress(0);
        L_processLabel.setText("");
        //System.out.println("开始下载: "+dlmnfs.getState());
        if (dlmnfs.getState().toString().contains("READY")) {
            dlmnfs.start();
        } else {
            dlmnfs.restart();
        }
    }

    @FXML
    private Button B_StartInstallNmon;

    @FXML
    void onActionStartInstallNmon(ActionEvent event) {
        Bar_process.setProgress(0);
        L_processLabel.setText("");
        //myupLoadNmonService.setDelay(Duration.seconds(1));
        //myupLoadNmonService.setPeriod(Duration.seconds(20));
        //System.out.println("开始上传: "+myupLoadNmonService.getState());
        if (myupLoadNmonService.getState().toString().contains("READY")) {
            myupLoadNmonService.start();
        } else {
            myupLoadNmonService.restart();
        }
    }


    @FXML
    void onActionStartMonitoring(ActionEvent event) {
        //System.out.println("开始监控");
        Bar_process.setProgress(0);
        L_processLabel.setText("");
        //判断是否延时
        if(CB_delay.isSelected()){
            //获取设置的延时时长 秒级
            int delaytime = Integer.parseInt(TF_delayed_h.getText())*60*60+Integer.parseInt(TF_delayed_min.getText())*60;
            System.out.println("延时: "+delaytime+" s");
            //启动延时任务 用于展示延时倒计时
            sjss.setDelay(Duration.seconds(delaytime));



            //判断延时时长是否超过10分钟
            if(delaytime>600){
                //当延时启动时，显示停止延时监控按钮
                L_nodelay.setText("取消");
                delayFlag = true;
                css.setDelay(Duration.seconds(delaytime-120));
                //先断开连接
                if (leftstatus.getText().contains("已连接")) {
                    pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
                    // System.out.println("serverSessionMap.size :"+serverSessionMap.size());
                    pf.setStr("断开连接中...");
                    pf.activateProgressBar();
                    if (dss.getState().toString().contains("READY")) {
                        dss.start();
                    } else {
                        dss.restart();
                    }
                }

                //连接
                if (css.getState().toString().contains("READY")) {
                    //pf.activateProgressBar();
                    css.start();
                } else {
                    //pf.activateProgressBar();
                    css.restart();
                }

                //已连接状态 直接执行
                if (sjss.getState().toString().contains("READY")) {
                    sjss.start();
                } else {
                    sjss.restart();
                }

                if (dts.getState().toString().contains("READY")) {
                    dts.start();
                } else {
                    dts.restart();
                }



            }else {
                //设定的延时小于10分钟 判断是否连接状态，不是则提示先连接
                if(leftstatus.getText().contains("未连接")){
                    System.out.println("当前未连接，请先连接相关服务器");
                }else {
                    //当延时启动时，显示停止延时监控按钮
                    L_nodelay.setText("取消");
                    delayFlag = true;
                    //执行延时任务，刷新倒计时状态
                    if (dts.getState().toString().contains("READY")) {
                        dts.start();
                    } else {
                        dts.restart();
                    }
                    //已连接状态 直接执行
                    if (sjss.getState().toString().contains("READY")) {
                        sjss.start();
                    } else {
                        sjss.restart();
                    }
                }

            }





            //设置监控任务延时
//            sjss.setDelay(Duration.seconds(delaytime));
//            //监控启动前10分钟重建与服务器连接
//            dss.setDelay(Duration.seconds(delaytime-12));
//            css.setDelay(Duration.seconds(delaytime-6));









//            //运行断开
//            if(delaytime>12){
//                if (leftstatus.getText().contains("已连接")) {
//                    serverSessionMap.clear();
//                    if (dss.getState().toString().contains("READY")) {
//                        dss.start();
//                    } else {
//                        dss.restart();
//                    }
//                    if (css.getState().toString().contains("READY")) {
//                        css.start();
//                    } else {
//                        css.restart();
//                    }
//                } else {
//                    serverSessionMap.clear();
//                    //获取连接
//                    if (css.getState().toString().contains("READY")) {
//                        css.start();
//                    } else {
//                        css.restart();
//                    }
//                }
//            }





        }else {//非延时情况下，
            //System.out.print("开始监控...");
            sjss.setDelay(Duration.seconds(1));
            if (sjss.getState().toString().contains("READY")) {
                sjss.start();
            } else {
                sjss.restart();
            }
        }

    }



    @FXML
    void onActionStopMonitoring(ActionEvent event) {
        //System.out.println("停止监控");
        Bar_process.setProgress(0);
        L_processLabel.setText("");
        if (stjss.getState().toString().contains("READY")) {
            stjss.start();
        } else {
            stjss.restart();
        }
    }

    @FXML
    void onActionUninstallNmon(ActionEvent event) {
        System.out.println("清除监控还没写+实验loading");
//        pf = new ProgressFrom((Stage)B_AnalyseNmonResult.getScene().getWindow());
//        pf.activateProgressBar();
        //System.out.println("sjss状态"+sjss.getState()+"sjss状态"+stjss.getState());
    }

    @FXML
    void OnEntered(DragEvent event) {
        System.out.println("bianhua");
    }

    @FXML
    void onInputMethodTextChanged(InputMethodEvent event) {
    }

    @FXML
    void OnkeyPressed(KeyEvent event) {
        if(event.getCode() == KeyCode.ENTER){
            TF_downloadPath1.setText(TF_MonitoringNmonName.getText());
            TF_downloadFileName.setText("*"+TF_MonitoringNmonName.getText()+"*.nmon");
        }
    }

    @FXML
    void onActionOpenDownloadPath(ActionEvent event) {
        //System.out.println("ksdjfsldjkfls");
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialDirectory(new File(TF_downloadPath.getText()+File.separator+TF_downloadPath1.getText()));
        fileChooser.setTitle("查看下载文件");
        fileChooser.getExtensionFilters().addAll(
                new FileChooser.ExtensionFilter("Text Files", "*.csv","*.nmon"),
                new FileChooser.ExtensionFilter("All Files", "*.*"));
        File selectedFile = fileChooser.showOpenDialog(null);
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    @FXML
    private Label rightstatus;

    @FXML
    private Label leftstatus;

    @FXML
    void onActionCopyServerConfiguration(ActionEvent event) {
        final Clipboard clipboard = Clipboard.getSystemClipboard();
        final ClipboardContent content = new ClipboardContent();
        String str = "服务器名称\tIP地址\t物理 核数 逻辑\t内存\t磁盘空间\tjava 版本\t主机名\t系统类型\t系统版本\t系统当前时间\r\n";
        for (int i = 0;i < dataList.size();i++){
            str = str+dataList.get(i).toString()+"\r\n";
        }
        content.putString(str);
        clipboard.setContent(content);
        System.out.println("已复制到粘贴板");
    }
    @FXML
    void onActionCopyTableview_MonitorHistoryList(ActionEvent event) {
        final Clipboard clipboard = Clipboard.getSystemClipboard();
        final ClipboardContent content = new ClipboardContent();
        String str = "id\t开始时间\t频率\t时长\t名称\t备注\t下载\t解析\t报告连接\r\n";
        for (int i = 0;i < monitorHistoryDataList.size();i++){
            str = str+monitorHistoryDataList.get(i).toString()+"\r\n";
        }
        content.putString(str);
        clipboard.setContent(content);
        System.out.println("监控记录 已复制到粘贴板");
    }


    @FXML
    private WebView webview;


    @FXML
    void nodelayOnMouseClicked(MouseEvent event) {
        dts.cancel();
        delayFlag = false;
        B_startMonitor.setDisable(false);
        B_stopMonitor.setDisable(false);
        System.out.println("取消延时监控");
        L_delayTime.setText("");
        L_nodelay.setText("");
        Bar_process.setProgress(0);

    }

    //监控片段相关属性已配置  tableview_Monitor 相关属性已配置
    @FXML
    private TableView<MonitorFragmentModel> tableview_Monitor;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_serverName_Monitor;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_hostIP_Monitor;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_CpuUse;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_CpuSys;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_CpuWait;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_CpuId;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_MemUse;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_LoadAvg;

    @FXML
    private TableColumn<MonitorFragmentModel, String> C_LoadAvgReference;

    @FXML
    private Button button_getMonitorConfiguration;

    //复制监控片段
    @FXML
    void onActionCopyMonitorConfiguration(ActionEvent event) {
        final Clipboard clipboard = Clipboard.getSystemClipboard();
        final ClipboardContent content = new ClipboardContent();
        String str = "应用名称\tIP地址\tCpu Use\tCpu Sys\tCpu Wait\tCpu Id\tMem Use\t\tLoad Avg\tLoad Avg 参考\r\n";
        for (int i = 0;i < monitorFragmentDataList.size();i++){
            str = str+monitorFragmentDataList.get(i).toString()+"\r\n";
        }
        content.putString(str);
        clipboard.setContent(content);
        System.out.println("当前监控片段信息 已复制到粘贴板");
    }


    //获取监控
    @FXML
    void onActionGetMonitorConfiguration(ActionEvent event) {
        pf= new ProgressFrom((Stage)UI_MAIN.getScene().getWindow());
        pf.setStr("获取信息中...");
        pf.activateProgressBar();
        if (gmcs.getState().toString().contains("READY")) {
            gmcs.start();
        } else {
            gmcs.restart();
        }
    }

    @FXML
    private void initialize() {

//        System.out.println("lall");
        // get the web engine
//        WebEngine we = webview.getEngine();
//
//        // load a website
//        we.load("https://www.baidu.com");



        //初始化
        //System.out.println("CheckTreeViewController初始化");

        //输出重定向logArea
        new Thread(()->{
            ps = new ConsolePrint(logArea);
            System.setOut(ps);
            //System.setErr(ps);
        }).start();


        //配置初始化
        try {
            //获取当前路径
            File file = new File("");
            String filePath = file.getCanonicalPath();
            String baseinfoPath = filePath + File.separator + "conf" + File.separator + "baseConf.properties";
            //System.out.println("当前路径为：" + baseinfoPath);
            GetBaseConf getBaseConf = new GetBaseConf();
            properties = getBaseConf.getProperties(baseinfoPath);
        } catch (Exception e) {
            e.printStackTrace();
        }


        //ServerInfo
        //初始化服务器内容展示
        DoServerInfo(properties.getProperty("serverInfoPath"));
        System.out.println("当前服务器信息文件为：" + properties.getProperty("serverInfoPath"));
        //初始化nmon监控页面显示内容
        TF_setNmonPath.setText(properties.getProperty("nmonPath"));
        TF_frequency.setText(properties.getProperty("frequency"));
        TF_duration.setText(properties.getProperty("time"));
        TF_counts.setDisable(true);
        TF_counts.setText(Integer.parseInt(TF_duration.getText()) * 60 / Integer.parseInt(TF_frequency.getText()) + " ");
//        System.out.println(TF_counts.getText());
        TF_downloadPath.setText(properties.getProperty("downloadPath"));
        TF_downloadFileName.setText("**.nmon");
        //设置右状态为服务器地址
        rightstatus.setText(properties.getProperty("serverInfoPath"));

        //监听 频率和监控时长
        TF_frequency.textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                TF_counts.setText(Integer.parseInt(TF_duration.getText()) * 60 / Integer.parseInt(TF_frequency.getText()) + " ");
            }
        });
        TF_duration.textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                TF_counts.setText(Integer.parseInt(TF_duration.getText()) * 60 / Integer.parseInt(TF_frequency.getText()) + " ");
            }
        });


        //设置左状态为未连接状态
        // 设置按钮文字的颜色
        /**
         * #CD0000 红色
         * #7CCD7C 绿色
         * #FFB90F 黄色
         * #778899 灰色
         */
        leftstatus.setTextFill(Paint.valueOf("#CD0000"));
        leftstatus.setText("未连接");

        //执行获取消息任务
//        getServiceBaseInfoScheduledService gsbs = new getServiceBaseInfoScheduledService();
//        //设定任务1秒后运行
//        gsbs.setDelay(Duration.seconds(1));
//        //设定任务没几秒运行一下
//        gsbs.setPeriod(Duration.seconds(1));
//        gsbs.start();

        //服务器信息表
        //加载数据源
        tableview.setItems(dataList);
        //tableview.getSelectionModel().setCellSelectionEnabled(false);
        tableview.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

        C_serverName.setPrefWidth(tableview.getPrefWidth()/10+20);
        C_hostIP.setPrefWidth(tableview.getPrefWidth()/10+20);
        C_CPU.setPrefWidth(tableview.getPrefWidth()/10+20);
        C_MEM.setPrefWidth(tableview.getPrefWidth()/10);
        C_diskSpace.setPrefWidth(tableview.getPrefWidth()/10);
        C_javaVersion.setPrefWidth(tableview.getPrefWidth()/10);
        C_hostName.setPrefWidth(tableview.getPrefWidth()/10+40);
        C_systemType.setPrefWidth(tableview.getPrefWidth()/10);
        C_systemVersion.setPrefWidth(tableview.getPrefWidth()/10+50);
        C_serverDate.setPrefWidth(tableview.getPrefWidth()/10+50);

        //压测记录表
        tableview_MonitorHistoryList.setItems(monitorHistoryDataList);
        //监听选中的行
//        tableview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ServerConfiguration>() {
//            @Override
//            public void changed(ObservableValue<? extends ServerConfiguration> observable, ServerConfiguration oldValue, ServerConfiguration newValue) {
//                System.out.println(newValue);
//            }
//        });
        // 监听某个单元格
        tableview_MonitorHistoryList.getSelectionModel().setCellSelectionEnabled(true);
        tableview_MonitorHistoryList.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
//                System.out.println(event.getClickCount()+","+Integer.parseInt(ActultablePosition[0]));
                if(event.getClickCount()>=2 && Integer.parseInt(ActultablePosition[0])==8){
//                    System.out.println("双击");
                    java.awt.Desktop dp = java.awt.Desktop.getDesktop();
//                        "file://"+obj.toString()+"index.html"
                    try {
                        dp.browse((new URI("file://"+ActultablePosition[1]+File.separator+"index.html")));
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.out.println("读取报告异常[ "+ActultablePosition[1].toString()+File.separator+"index.html"+" ]");
                    }
                }

            }
        });
        tableview_MonitorHistoryList.getSelectionModel().getSelectedCells().addListener(new InvalidationListener() {
            @Override
            public void invalidated(Observable observable) {
//                System.out.println(observable);
                ObservableList<TablePosition> obs = ( ObservableList<TablePosition>)observable;
                for (TablePosition tbs: obs) {

//                    file:///Users/wutongchun/IdeaProjects/javaFX/javaFX_ToolsSummary/nmonResult/ceshijiankong/index.html

                            Object obj = tbs.getTableColumn().getCellData(tbs.getRow());
                            //把坐标值，和单元格内容传出去
                            ActultablePosition = new String[]{tbs.getColumn()+"",obj.toString()};



                }
            }
        });



//        tableview.getScene().getAccelerators()
//                .put(new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY), new Runnable() {
//                    @Override
//                    public void run() {
//                        int row = tableview.getSelectionModel().getSelectedIndex();
//                        ServerConfiguration tmp = tableview.getItems().get(row);
//                        final Clipboard clipboard = Clipboard.getSystemClipboard();
////                        final ClipboardContent content = new ClipboardContent();
////                        if(tableview.getSelectionModel().isSelected(row, numColumn)){
////                            System.out.println(tmp.getNumSlices());
////                            content.putString(tmp.getNumSlices().toString());
////                        }
////                        else{
////                            System.out.println(tmp.getSelected());
////                            content.putString(tmp.getSelected());
////                        }
//                        //clipboard.setContent(content);
//                    }
//                });



        //添加数据源数据到列中
        C_serverName.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().serverNameProperty();
            }
        });
        C_hostIP.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().hostIPProperty();
            }
        });
        C_CPU.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().CPUProperty();
            }
        });
        C_MEM.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().MEMProperty();
            }
        });
        C_diskSpace.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().diskSpaceProperty();
            }
        });
        C_javaVersion.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().javaVersionProperty();
            }
        });
        C_hostName.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().hostNameProperty();
            }
        });
        C_systemType.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().systemTypeProperty();
            }
        });
        C_systemVersion.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().systemVersionProperty();
            }
        });
        C_serverDate.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ServerConfigurationModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ServerConfigurationModel, String> param) {
                return param.getValue().serverDateProperty();
            }
        });


        tableview_MonitorHistoryList.setEditable(true);
        //添加压测监控日志记录数据源数据到列中
        C_id.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().idProperty();
            }
        });

        C_startTime.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().startTimeProperty();
            }
        });
        C_frequency.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().frequencyProperty();
            }
        });
        C_duration.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().durationProperty();
            }
        });
        C_nmonName.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().nmonNameProperty();
            }
        });
        //设置nmonName列可编辑
        C_nmonName.setCellFactory(TextFieldTableCell.forTableColumn());
        C_PS.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().PSProperty();
            }
        });
        //C_PS
        C_PS.setCellFactory(TextFieldTableCell.forTableColumn());
        C_isDownload.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().isDownloadProperty();
            }
        });
        C_isAnalysis.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().isAnalysisProperty();
            }
        });
        C_toLink.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NmonMonitorListModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<NmonMonitorListModel, String> param) {
                return param.getValue().toLinkProperty();
            }
        });
        //C_toLink
        C_toLink.setCellFactory(TextFieldTableCell.forTableColumn());

        //监控片段表
        tableview_Monitor.setItems(monitorFragmentDataList);
        //添加数据源数据到监控片段表的列中
        C_serverName_Monitor.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().serverName_MonitorProperty();
            }
        });
        C_hostIP_Monitor.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().hostIP_MonitorProperty();
            }
        });
        C_CpuUse.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().CpuUseProperty();
            }
        });
        C_CpuSys.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().CpuSysProperty();
            }
        });
        C_CpuWait.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().CpuWaitProperty();
            }
        });
        C_CpuId.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().CpuIdProperty();
            }
        });
        C_MemUse.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().MemUseProperty();
            }
        });
        C_LoadAvg.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().LoadAvgProperty();
            }
        });
        C_LoadAvgReference.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<MonitorFragmentModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<MonitorFragmentModel, String> param) {
                return param.getValue().LoadAvgReferenceProperty();
            }
        });

        //监控片段表
        tableview_ZDY.setItems(ZDYDataList);
        tableview_ZDY.setEditable(true);
        //设置 C_ServerName_ZDY 列可编辑
        C_ServerName_ZDY.setCellFactory(TextFieldTableCell.forTableColumn());
        C_ServerName_ZDY.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ZDYdataModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ZDYdataModel, String> param) {
                return param.getValue().serverName_ZDYProperty();
            }
        });
        //设置 C_IP_ZDY 列可编辑
        C_IP_ZDY.setCellFactory(TextFieldTableCell.forTableColumn());
        C_IP_ZDY.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ZDYdataModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ZDYdataModel, String> param) {
                return param.getValue().hostIP_ZDYProperty();
            }
        });
        //设置C_MyCommand1列可编辑
        C_MyCommand1.setCellFactory(TextFieldTableCell.forTableColumn());
        C_MyCommand1.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ZDYdataModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ZDYdataModel, String> param) {
                return param.getValue().MyCommand1Property();
            }
        });
        //设置C_MyCommand2列可编辑
        C_MyCommand2.setCellFactory(TextFieldTableCell.forTableColumn());
        C_MyCommand2.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ZDYdataModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ZDYdataModel, String> param) {
                return param.getValue().MyCommand2Property();
            }
        });
        //设置C_MyCommand3列可编辑
        C_MyCommand3.setCellFactory(TextFieldTableCell.forTableColumn());
        C_MyCommand3.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ZDYdataModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ZDYdataModel, String> param) {
                return param.getValue().MyCommand3Property();
            }
        });
        //设置C_MyCommand4列可编辑
        C_MyCommand4.setCellFactory(TextFieldTableCell.forTableColumn());
        C_MyCommand4.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ZDYdataModel, String>, ObservableValue<String>>() {
            @Override
            public ObservableValue<String> call(TableColumn.CellDataFeatures<ZDYdataModel, String> param) {
                return param.getValue().MyCommand4Property();
            }
        });





//        sjss.messageProperty().addListener(new ChangeListener<String>() {
//            @Override
//            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
//                System.out.println(newValue);
//            }
//        });
//
//        sjss.valueProperty().addListener(new ChangeListener<Number>() {
//            @Override
//            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
//                System.out.println("--"+newValue);
//            }
//        });
        dts.messageProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                if(newValue != ""){
                    if(Integer.parseInt(newValue)>=1&&delayFlag){
                        L_delayTime.setText("倒计时 "+newValue+" s");
                    }
                }
            }
        });

        //创建数据库连接
        h2dbCRUDUtil = new H2dbCRUDUtil(properties.getProperty("dbConnectURL"));
        h2dbCRUDUtil.connect();


//        新建表
        h2dbCRUDUtil.createSql("CREATE TABLE IF NOT EXISTS nmonMonitorList_table(" +
                    "id bigint auto_increment PRIMARY KEY," +
                    "startTime TIMESTAMP," +//TIMESTAMP
                    "frequency INT(5)," +
                    "duration INT(10)," +
                    "nmonName VARCHAR(200)," +
                    "PS VARCHAR(200)," +
                    "isDownload VARCHAR(10)," +
                    "isAnalysis VARCHAR(10)," +
                    "toLink VARCHAR(200)" +
                    ")");
            ////插入表数据
//        //h2dbCRUDUtil.insertOrUpdateSql("INSERT INTO nmonMonitorList_table VALUES('2020-04-03 10:30:30.123')");
//        h2dbCRUDUtil.insertOrUpdateSql("INSERT INTO nmonMonitorList_table" +
//                "(startTime,frequency,duration,nmonName,PS,isDownload,isAnalysis,toLink)" +
//                " VALUES" +
//                "('2020-04-03 10:30:30.124','1','2','nmonname','ps','true','false','xxxx')" +
//                "");
////        //查询表数据
//        ResultSet result = h2dbCRUDUtil.selectSql("select * from nmonMonitorList_table");
//        int i=0;
//        try {
//            while (result.next()) {
//                System.out.println(
//                        result.getInt("id") + ", " +
//                        result.getString("startTime") + ", " +
//                        result.getInt("frequency") + ", " +
//                        result.getInt("duration") + ", " +
//                        result.getString("nmonName") + ", " +
//                        result.getString("PS") + ", " +
//                        result.getString("isDownload") + ", " +
//                        result.getString("isAnalysis") + ", " +
//                        result.getString("toLink") + ", "
//                );
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }





        //h2dbCRUDUtil.insertOrUpdateSql("INSERT INTO nmonMonitorList_table VALUES(1,'2020-04-03 10:30:30.123')");
        //h2dbCRUDUtil.insertOrUpdateSql("INSERT INTO nmonMonitorList_table VALUES('2020-04-03 10:30:30.123', '1', '1', 'dfssd', 'sdfs',true,true,'kkkkkk')");
        //h2dbCRUDUtil.insertOrUpdateSql("UPDATE nmonMonitorList_table SET isDownload = 'true' WHERE nmonName like '%sdfsdf%'");

        //h2dbCRUDUtil.createSql("delete from nmonMonitorList_table");
        //初始化历史记录表
        //读取配置文件中历史表的位置
        //判断库文件是否存在 不存在则创建文件
        //创建历史表是否存在 不存在则新建表
        //读取表内容 并赋值给tableview
        ResultSet result = h2dbCRUDUtil.selectSql("select * from nmonMonitorList_table");
        try {
            while (result.next()) {
//                System.out.println(
//                        result.getInt("id") + ", " +
//                        result.getString("startTime") + ", " +
//                        result.getInt("frequency") + ", " +
//                        result.getInt("duration") + ", " +
//                        result.getString("nmonName") + ", " +
//                        result.getString("PS") + ", " +
//                        result.getString("isDownload") + ", " +
//                        result.getString("isAnalysis") + ", " +
//                        result.getString("toLink") + ", "
//                );
//            monitorHistoryDataList.add(new NmonMonitorListModel("1","1","1","1","1","1","1","1"));
                int i = result.getInt("id");
            monitorHistoryDataList.add(result.getInt("id")-1,
                    new NmonMonitorListModel(result.getString("id"),
                            result.getString("startTime"),
                            result.getString("frequency"),
                            result.getString("duration"),
                            result.getString("nmonName"),
                            result.getString("PS"),
                            result.getString("isDownload"),
                            result.getString("isAnalysis"),
                            result.getString("toLink")));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
//        TF_downloadFileName.setText("*sdfsdf*.nmon");
        //h2dbCRUDUtil.insertOrUpdateSql("UPDATE nmonMonitorList_table SET isDownload = 'false' WHERE nmonName like '%"+TF_downloadFileName.getText().replace("*.nmon","").replace("*","")+"%'");
//        ResultSet resultSet = h2dbCRUDUtil.selectSql("Select id from nmonMonitorList_table where nmonName like '%"+TF_downloadFileName.getText().replace("*.nmon","").replace("*","")+"%'");
//        try {
//            while (resultSet.next()){
//                monitorHistoryDataList.get(resultSet.getInt("id")-1).setIsDownload("sdfsd");
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//            System.out.println(e.getMessage());
//        }





        //System.out.println("主线程名称"+Thread.currentThread().getName());

//         System.out.println("This is println message.");
//
//         //logger.addAppender(myTextAreaAppender);
//         //记录debug级别的信息
//        logger.debug("This is debug message.");
//        // 记录info级别的信息
//        logger.info("This is info message.");
//        // 记录error级别的信息
//        logger.error("This is error message.");


        //启一个http服务用户 分析记录写入到文件中
        try {
            new WebApi().run();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    //ServerInfo
    //初始化服务器内容，包括checkbox的赋值
    public void DoServerInfo(String path) {
        serverInfo = new ServerInfo(path);
        CheckBoxTreeItem<String> root = serverInfo.getServerInfo();
        root.setExpanded(true);
        CheckTreeView_hostIP.setRoot(root);
        //checkbox添加监听事件，监听服务器是否选中，利用的求差集的方式
        CheckTreeView_hostIP.getCheckModel().getCheckedItems().addListener(new ListChangeListener<TreeItem<String>>() {
            public void onChanged(Change<? extends TreeItem<String>> c) {
                //System.out.println(CheckTreeView_hostIP.getCheckModel().getCheckedItems());
                //System.out.println(c.getList());
                //System.out.println("---------");
                List list = c.getList();
                //for (int i=0;i<list.size();i++){
//                    System.out.println("i="+i+","+list.get(i));
//                    System.out.println(IpRegEx.getIps(list.get(i).toString()));
//                    System.out.println("-----");
                serverInfo.setServerMap(IpRegEx.getIps(list.toString()));
                //}
            }
        });
        //第二种获取选中集的方式是什么，遍历列表，判断是否选中


    }


    //监听sout输出项打印到日志显示模块
    public class ConsolePrint extends PrintStream {//可以正常解析utf8和gbk码
        TextArea console;

        public ConsolePrint(TextArea console) {
            super(new ByteArrayOutputStream());
            this.console = console;
        }

        @Override
        public void write(byte[] buf, int off, int len) {
            print(new String(buf, off, len));
        }

        @Override
        public void print(String s) {
            console.appendText(s);
        }
    }
    public class Console extends OutputStream {
        private TextArea console;

        public Console(TextArea console) {
            this.console = console;
        }

        public void appendText(String valueOf) {
            console.appendText(valueOf);
        }

        public void write(int b) throws IOException {
            appendText(String.valueOf((char) b));//这里解析非ascii码会出错乱码
        }
    }

    //获取基础路径
    //读取默认配置，避免每次打开都需要设置
    public String methodbasePath() throws IOException {
        //获取当前路径
        File file = new File("");
        String filePath = file.getCanonicalPath();
        //System.out.println("当前路径为：" + filePath);
//        //获取配置文件路径
//        String confpath = filePath+"/conf/base.conf";
//        //获取nmon执行文件路径
//        String nmonpath = filePath+"/nmon/linux/";
        return filePath;
    }

    //获取服务器基础信息的任务
    private class getServiceBaseInfoService extends Service<Number> {
        double statu = 0;
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void running() {
                    super.running();
                    tableview.setPlaceholder(new Label("获取中...."));
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    tableview.setPlaceholder(new Label("表格无数据"));
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    tableview.setPlaceholder(new Label(""));
                }

                @Override
                protected void failed() {
                    super.failed();
                    tableview.setPlaceholder(new Label("获取失败"));
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value.intValue() < 0) {
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        button_getServerConfiguration.setDisable(false);
                        pf.cancelProgressBar();
                    } else if (value.intValue() == 1) {
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            button_getServerConfiguration.setDisable(false);
                            pf.cancelProgressBar();
                    } else if (value.intValue() == 404 ){
                        button_getServerConfiguration.setDisable(false);
                        pf.cancelProgressBar();
                    }
                }

                @Override
                protected Number call()  {
                    //刷新数据前，先清除原数
                    dataList.clear();
                    //主要处理任务的地方
                    String[] serverBaseInfo = new String[9];
                    Long startTime2 = System.currentTimeMillis();

                    GetBaseInfo gbi = new GetBaseInfo(serverInfo.getMyUseServerMap(), serverSessionMap, 0);
                    //创建执行服务
                    ExecutorService ser = Executors.newFixedThreadPool(Integer.parseInt(properties.getProperty("getServiceBaseInfoService_FixedThreadPool")));
                    List<Future<ServerConfigurationModel>> resultList = new ArrayList<Future<ServerConfigurationModel>>();


                    //创建线程执行
                    if (serverSessionMap.size() > 0) {
                        //任务执行时 将获取按钮置灰，防止多按

//                        pf.activateProgressBar();
                        button_getServerConfiguration.setDisable(true);


                        statu = 1;
                        //创建线程执行
                        for (int i = 1; i <= serverInfo.getMyUseServerMap().size(); i++) {
                            try {
                                resultList.add(i - 1, ser.submit(gbi));
                            }catch (Exception e){
                                System.out.println(serverInfo.getMyUseServerMap().get(i-1)+"获取服务器信息"+e.getMessage());
                            }
                        }
                        ser.shutdown();
                        for (Future<ServerConfigurationModel> fs : resultList) {
                            try {
                                if(fs.get()!=null){
                                    dataList.add(fs.get());
                                    count++;
                                } else {
                                    statu = -1;
                                    count++;
                                    System.out.print("部分服务器未连接或连接异常，无法获取其服务器相关信息");
                                }
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            } catch (ExecutionException e) {
                                e.printStackTrace();
                            }

                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }





                    } else {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("请连接/重新连接");
                        return progress=404;
                    }
                    return null;
                }
            };
            return task;
        }
    }

    //获取监控片段信息的任务
    private class getMonitorConfigurationService extends Service<Number> {
        double statu = 0;
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void running() {
                    super.running();
                    tableview_Monitor.setPlaceholder(new Label("获取中...."));
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    tableview_Monitor.setPlaceholder(new Label("表格无数据"));
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    tableview_Monitor.setPlaceholder(new Label(""));
                }

                @Override
                protected void failed() {
                    super.failed();
                    tableview_Monitor.setPlaceholder(new Label("获取失败"));
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value.intValue() < 0) {
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        button_getMonitorConfiguration.setDisable(false);
                        pf.cancelProgressBar();
                    } else if (value.intValue() == 1) {
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        button_getMonitorConfiguration.setDisable(false);
                        pf.cancelProgressBar();
                    } else if (value.intValue() == 404 ){
                        button_getMonitorConfiguration.setDisable(false);
                        pf.cancelProgressBar();
                    }
                }

                @Override
                protected Number call()  {
                    //刷新数据前，先清除原数
                    monitorFragmentDataList.clear();
                    //主要处理任务的地方
                    String[] serverBaseInfo = new String[9];
                    Long startTime2 = System.currentTimeMillis();

                    GetMonitorFragment gmf = new GetMonitorFragment(serverInfo.getMyUseServerMap(), serverSessionMap, 0);
                    //创建执行服务
                    ExecutorService ser = Executors.newFixedThreadPool(Integer.parseInt(properties.getProperty("getServiceBaseInfoService_FixedThreadPool")));
                    List<Future<MonitorFragmentModel>> resultList = new ArrayList<Future<MonitorFragmentModel>>();


                    //创建线程执行
                    if (serverSessionMap.size() > 0) {
                        //任务执行时 将获取按钮置灰，防止多按

//                        pf.activateProgressBar();
                        button_getMonitorConfiguration.setDisable(true);


                        statu = 1;
                        //创建线程执行
                        for (int i = 1; i <= serverInfo.getMyUseServerMap().size(); i++) {
                            try {
                                resultList.add(i - 1, ser.submit(gmf));
                            }catch (Exception e){
                                System.out.println(serverInfo.getMyUseServerMap().get(i-1)+"获取服务器信息"+e.getMessage());
                            }
                        }
                        ser.shutdown();
                        for (Future<MonitorFragmentModel> fs : resultList) {
                            try {
                                if(fs.get()!=null){
                                    monitorFragmentDataList.add(fs.get());
                                    count++;
                                } else {
                                    statu = -1;
                                    count++;
                                    System.out.print("部分服务器未连接或连接异常，无法获取其服务器相关信息");
                                }
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            } catch (ExecutionException e) {
                                e.printStackTrace();
                            }

                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }





                    } else {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("请连接/重新连接");
                        return progress=404;
                    }
                    return null;
                }
            };
            return task;
        }
    }

    //获取监控片段信息的任务
    private class getZDYdataService extends Service<Number> {
        double statu = 0;
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void running() {
                    super.running();
                    tableview_ZDY.setPlaceholder(new Label("获取中...."));
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    tableview_ZDY.setPlaceholder(new Label("表格无数据"));
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    tableview_ZDY.setPlaceholder(new Label(""));
                }

                @Override
                protected void failed() {
                    super.failed();
                    tableview_ZDY.setPlaceholder(new Label("获取失败"));
                }

                @Override
                protected void updateValue(Number value) {// TODO: 2021/8/6
                    super.updateValue(value);
                    if (value.intValue() < 0) {
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        B_ZDYexcute.setDisable(false);
                        pf.cancelProgressBar();
                    } else if (value.intValue() == 1) {
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        B_ZDYexcute.setDisable(false);
                        pf.cancelProgressBar();
                    } else if (value.intValue() == 404 ){
                        B_ZDYexcute.setDisable(false);
                        pf.cancelProgressBar();
                    }
                }

                @Override
                protected Number call()  {
                    //刷新数据前，先清除原数
                    ZDYDataList.clear();
                    //主要处理任务的地方
                    String[] serverBaseInfo = new String[5];
                    Long startTime2 = System.currentTimeMillis();

                    GetZDYdata gzd = new GetZDYdata(serverInfo.getMyUseServerMap(), serverSessionMap, 0);
                    gzd.SetMyCommand(CB_MyCommand1.isSelected(),CB_MyCommand2.isSelected(),CB_MyCommand3.isSelected(),CB_MyCommand4.isSelected(),TF_MyCommand1.getText(),TF_MyCommand2.getText(),TF_MyCommand3.getText(),TF_MyCommand4.getText());
                    //创建执行服务
                    ExecutorService ser = Executors.newFixedThreadPool(Integer.parseInt(properties.getProperty("getServiceBaseInfoService_FixedThreadPool")));
                    List<Future<ZDYdataModel>> resultList = new ArrayList<Future<ZDYdataModel>>();


                    //创建线程执行
                    if (serverSessionMap.size() > 0) {
                        //任务执行时 将获取按钮置灰，防止多按

//                        pf.activateProgressBar();
                        B_ZDYexcute.setDisable(true);


                        statu = 1;
                        //创建线程执行
                        for (int i = 1; i <= serverInfo.getMyUseServerMap().size(); i++) {
                            try {
                                resultList.add(i - 1, ser.submit(gzd));
                            }catch (Exception e){
                                System.out.println(serverInfo.getMyUseServerMap().get(i-1)+"获取服务器信息"+e.getMessage());
                            }
                        }
                        ser.shutdown();
                        for (Future<ZDYdataModel> fs : resultList) {
                            try {
                                if(fs.get()!=null){
                                    ZDYDataList.add(fs.get());
                                    count++;
                                } else {
                                    statu = -1;
                                    count++;
                                    System.out.print("部分服务器未连接或连接异常，无法获取其服务器相关信息");
                                }
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            } catch (ExecutionException e) {
                                e.printStackTrace();
                            }

                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }





                    } else {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("请连接/重新连接");
                        return progress=404;
                    }
                    return null;
                }
            };
            return task;
        }
    }

    //获取部署nmon到服务器的任务
    private class upLoadNmonService extends Service<Number> {
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {

                @Override
                protected void running() {
                    super.running();
                    L_processLabel.setText("nmon上传中..");
                    B_StartInstallNmon.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    B_StartInstallNmon.setDisable(false);
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    B_StartInstallNmon.setDisable(false);
                }

                @Override
                protected void failed() {
                    super.failed();
                    B_StartInstallNmon.setDisable(false);
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);

                    if (value.intValue() < 0) {
                        L_processLabel.setText("");
                        B_StartInstallNmon.setDisable(false);
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        upLoadNmonService.this.cancel();
                    } else {
                        Bar_process.setProgress(value.doubleValue());
                        if (value.intValue() >= 1) {
                            L_processLabel.setText("上传完成");
                            B_StartInstallNmon.setDisable(false);
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            upLoadNmonService.this.cancel();
                        }
                    }

                }
                @Override
                protected Number call() {

                    String user = "";// 用户名
                    String pwd = "";// 密码
                    String ip = "";// 服务器地址
                    String nmonpath = "";
                    int port = 22;// 端口号
                    int timeout = 10000000;
                    String nmonbushulujing = TF_setNmonPath.getText();
                    String nmonPath_linux ="";
                    String nmonPath_unix ="";

                    try {
                         nmonPath_linux = methodbasePath() + File.separator + "myNmon" + File.separator + "Linux" + File.separator + "nmon";
                         nmonPath_unix = methodbasePath() + File.separator + "myNmon" + File.separator + "Unix" + File.separator + "nmon";
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
                    //输入项不允许为空
                    double i = 1.0;
                    if (leftstatus.getText().contains("未连接")) {
                        System.out.println("error :  当前未连接状态");
                        return -1;
                    } else if (TF_setNmonPath.getText().length() == 0) {
                        System.out.println("error :  请输入服务器监控部署路径!");
                        return -1;
                    } else {
                        while (iterator.hasNext()) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            count++;
                            //用户3种情况
                            /**
                             * ~/myNmon 目录 普通用户  ~ 替换 /home/用户名/myNmon
                             * ~/myNmon 目录 root用户 ~ 替换 /用户名/myNmon
                             * /home/myNmon   不需要修改和替换
                             */
                            String[] values = (String[]) entry.getValue();
                            String key = (String) entry.getKey();
                            user = values[1];
                            ip = key;
                            pwd = values[2];
                            nmonpath = values[3];
//
                            //部署路径处理
                            if (nmonpath.toUpperCase().contains("DEFAULT") && TF_setNmonPath.getText().contains("~/")) {
                                if (user.toUpperCase().contains("ROOT")) {
                                    nmonbushulujing = TF_setNmonPath.getText().replace("~", "/" + user);
                                } else {
                                    nmonbushulujing = TF_setNmonPath.getText().replace("~", "/home/" + user);
                                }
                            } else {
                                nmonbushulujing = nmonpath.toString();
                            }
                            Session session = serverSessionMap.get(key.toString());
                           //System.out.println("session ip:"+session.getHost()+";session 状态:"+session.getClientVersion());

                            //开始部署
                            //判断部署路径是否存在
                            String result = null;
                            try {
                                result = execCommandByJSch(session, "if [ ! -d \"" + nmonbushulujing + "\" ];then echo 0;else echo 1;fi", "UTF-8");
                            } catch (IOException e) {
                                e.printStackTrace();
                                System.out.println(key+"1.获取内容异常");
                                return -1;
                            } catch (JSchException e) {
                                e.printStackTrace();
                                System.out.println(key+"2连接异常");
                                return -1;
                            }

                            if (result.contains("0")) {
                                System.out.println(key.toString() + " 文件夹不存在，开始创建!");
                                //判断文件夹创建是否成功
                                try {
                                    result = execCommandByJSch(session, "mkdir " + nmonbushulujing, "UTF-8");
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.out.println(key+"3创建文件夹异常");
                                }
                                if (result.length() == 0) {
                                    System.out.println(key.toString() + "文件夹创建成功,开始上传nmon文件");
                                    SFTPUtil sftp = new SFTPUtil(ip, port, user, pwd);
//                            System.out.println(new StringBuffer().append(" 服务器地址: ")
//                                    .append(sftp.getHostName()).append(" 端口：").append(sftp.getPort())
//                                    .append("用户名：").append(sftp.getUserName()).append("密码:")
//                                    .append(sftp.getPassword().toString()));
                                    try {
                                        sftp.connect();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        System.out.println(key+"4sftp服务连接异常");
                                        return -1;
                                    }
                                    //开始上传文件，判断系统为linux aix 或 unix
                                    boolean isexist = false;
                                    try {
                                        isexist = sftp.isExist(nmonbushulujing);
                                    } catch (SftpException e) {
                                        e.printStackTrace();
                                        System.out.println(key+"5文件部署路径不存在");
                                        return -1;
                                    }

                                    if (isexist) {
                                        try {
                                            if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
                                                sftp.uploadFile(nmonbushulujing, "nmon", nmonPath_unix);
                                                execCommandByJSch(session, "chmod +x " + nmonbushulujing + "/nmon", "UTF-8");
                                            } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
                                                sftp.uploadFile(nmonbushulujing, "nmon", nmonPath_linux);
                                                execCommandByJSch(session, "chmod +x " + nmonbushulujing + "/nmon", "UTF-8");
                                            } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
                                                System.out.println("IP:" + sftp.getHostName() + "为AIX系统，无需上传");
                                            }
                                        }catch (Exception e){
                                            e.printStackTrace();
                                        }

                                    }

                                } else {
                                    System.out.println(key.toString() + "文件夹创建失败");
                                }
                            } else {
                                System.out.print(key.toString() + " : Nmon监控文件夹已经存在!...开始上传nmon文件...");
                                SFTPUtil sftp = new SFTPUtil(ip, port, user, pwd);
//                            System.out.println(new StringBuffer().append(" 服务器地址: ")
//                                    .append(sftp.getHostName()).append(" 端口：").append(sftp.getPort())
//                                    .append("用户名：").append(sftp.getUserName()).append("密码:")
//                                    .append(sftp.getPassword().toString()));
                                try {
                                    sftp.connect();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.out.println(key+"4sftp服务连接异常");
                                    return -1;
                                }
                                //开始上传文件，判断系统为linux aix 或 unix
                                boolean isexist = false;
                                try {
                                    isexist = sftp.isExist(nmonbushulujing);
                                } catch (SftpException e) {
                                    e.printStackTrace();
                                    System.out.println(key+"5文件部署路径不存在");
                                    return -1;
                                }
                                if (isexist) {
                                    try {
                                        if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
                                            sftp.uploadFile(nmonbushulujing, "nmon", nmonPath_unix);
                                            execCommandByJSch(session, "chmod +x " + nmonbushulujing + "/nmon", "UTF-8");
                                        } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
                                            sftp.uploadFile(nmonbushulujing, "nmon", nmonPath_linux);
                                            execCommandByJSch(session, "chmod +x " + nmonbushulujing + "/nmon", "UTF-8");
                                        } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
                                            System.out.println("IP:" + sftp.getHostName() + "为AIX系统，无需上传");
                                        }
                                    }catch (Exception e){
                                        e.printStackTrace();
                                        System.out.println(key+"上传异常"+e.getMessage());
                                    }
                                }
                                System.out.println("上传成功");
                            }

                            //进度计算
                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }
                    }
                    return null;
                }


            };
            return task;
        }
    }

    //获取部署nmon到服务器的任务
    private class ZDYupLoadFileService extends Service<Number> {
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {

                @Override
                protected void running() {
                    super.running();
                    L_processLabel.setText("文件上传中..");
                    B_ZDY_upload.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    B_ZDY_upload.setDisable(false);
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    B_ZDY_upload.setDisable(false);
                }

                @Override
                protected void failed() {
                    super.failed();
                    B_ZDY_upload.setDisable(false);
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);

                    if (value.intValue() < 0) {
                        L_processLabel.setText("");
                        B_ZDY_upload.setDisable(false);
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        ZDYupLoadFileService.this.cancel();
                    } else {
                        Bar_process.setProgress(value.doubleValue());
                        if (value.intValue() >= 1) {
                            L_processLabel.setText("上传完成");
                            B_ZDY_upload.setDisable(false);
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            ZDYupLoadFileService.this.cancel();
                        }
                    }

                }
                @Override
                protected Number call() {

                    String user = "";// 用户名
                    String pwd = "";// 密码
                    String ip = "";// 服务器地址
                    String nmonpath = "";
                    int port = 22;// 端口号
                    int timeout = 10000000;
                    String nmonbushulujing = TF_ServiceAbsolutePath.getText();
                    String nmonPath_linux ="";
                    String nmonPath_unix ="";
                    String nmonPath_Aix = "";

                    try {
                        nmonPath_linux = TF_FileAbsolutePath.getText();
                        nmonPath_unix = TF_FileAbsolutePath.getText();
                        nmonPath_Aix = TF_FileAbsolutePath.getText();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
                    //输入项不允许为空
                    double i = 1.0;
                    if (leftstatus.getText().contains("未连接")) {
                        System.out.println("error :  当前未连接状态");
                        return -1;
                    } else if (TF_setNmonPath.getText().length() == 0) {
                        System.out.println("error :  请输入服务器监控部署路径!");
                        return -1;
                    } else {
                        while (iterator.hasNext()) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            count++;
                            //用户3种情况
                            /**
                             * ~/myNmon 目录 普通用户  ~ 替换 /home/用户名/myNmon
                             * ~/myNmon 目录 root用户 ~ 替换 /用户名/myNmon
                             * /home/myNmon   不需要修改和替换
                             */
                            String[] values = (String[]) entry.getValue();
                            String key = (String) entry.getKey();
                            user = values[1];
                            ip = key;
                            pwd = values[2];
//
                            Session session = serverSessionMap.get(key.toString());
                            //System.out.println("session ip:"+session.getHost()+";session 状态:"+session.getClientVersion());

                            //开始上传
                            //判断上传路径是否存在
                            String result = null;
                            try {
                                result = execCommandByJSch(session, "if [ ! -d \"" + nmonbushulujing + "\" ];then echo 0;else echo 1;fi", "UTF-8");
                            } catch (IOException e) {
                                e.printStackTrace();
                                System.out.println(key+"1.获取内容异常");
                                return -1;
                            } catch (JSchException e) {
                                e.printStackTrace();
                                System.out.println(key+"2连接异常");
                                return -1;
                            }

                            if (result.contains("0")) {
                                System.out.println(key.toString() + " 文件夹不存在，开始创建!");
                                //判断文件夹创建是否成功
                                try {
                                    result = execCommandByJSch(session, "mkdir " + nmonbushulujing, "UTF-8");
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.out.println(key+"3创建文件夹异常");
                                }
                                if (result.length() == 0) {
                                    System.out.println(key.toString() + "文件夹创建成功,开始上传nmon文件");
                                    SFTPUtil sftp = new SFTPUtil(ip, port, user, pwd);
//                            System.out.println(new StringBuffer().append(" 服务器地址: ")
//                                    .append(sftp.getHostName()).append(" 端口：").append(sftp.getPort())
//                                    .append("用户名：").append(sftp.getUserName()).append("密码:")
//                                    .append(sftp.getPassword().toString()));
                                    try {
                                        sftp.connect();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        System.out.println(key+"4sftp服务连接异常");
                                        return -1;
                                    }
                                    //开始上传文件，判断系统为linux aix 或 unix
                                    boolean isexist = false;
                                    try {
                                        isexist = sftp.isExist(nmonbushulujing);
                                    } catch (SftpException e) {
                                        e.printStackTrace();
                                        System.out.println(key+"5文件部署路径不存在");
                                        return -1;
                                    }

                                    if (isexist) {
                                        try {
                                            if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
                                                sftp.uploadFile(nmonbushulujing, TF_FileName.getText(), nmonPath_unix);
                                            } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
                                                sftp.uploadFile(nmonbushulujing, TF_FileName.getText(), nmonPath_linux);
                                            } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
                                                sftp.uploadFile(nmonbushulujing, TF_FileName.getText(), nmonPath_Aix);
                                            }
                                        }catch (Exception e){
                                            e.printStackTrace();
                                        }

                                    }

                                } else {
                                    System.out.println(key.toString() + "文件夹创建失败");
                                }
                            } else {
                                System.out.print(key.toString() + " : 文件夹已经存在!...开始上传文件...");
                                SFTPUtil sftp = new SFTPUtil(ip, port, user, pwd);
//                            System.out.println(new StringBuffer().append(" 服务器地址: ")
//                                    .append(sftp.getHostName()).append(" 端口：").append(sftp.getPort())
//                                    .append("用户名：").append(sftp.getUserName()).append("密码:")
//                                    .append(sftp.getPassword().toString()));
                                try {
                                    sftp.connect();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.out.println(key+"4sftp服务连接异常");
                                    return -1;
                                }
                                //开始上传文件，判断系统为linux aix 或 unix
                                boolean isexist = false;
                                try {
                                    isexist = sftp.isExist(nmonbushulujing);
                                } catch (SftpException e) {
                                    e.printStackTrace();
                                    System.out.println(key+"5文件部署路径不存在");
                                    return -1;
                                }
                                if (isexist) {
                                    try {
                                        if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
                                            sftp.uploadFile(nmonbushulujing, TF_FileName.getText(), nmonPath_unix);
                                        } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
                                            sftp.uploadFile(nmonbushulujing, TF_FileName.getText(), nmonPath_linux);
                                        } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
                                            sftp.uploadFile(nmonbushulujing, TF_FileName.getText(), nmonPath_Aix);
                                        }
                                    }catch (Exception e){
                                        e.printStackTrace();
                                        System.out.println(key+"上传异常"+e.getMessage());
                                    }
                                }
                                System.out.println("上传成功");
                            }

                            //进度计算
                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }
                    }
                    return null;
                }


            };
            return task;
        }
    }

    //获取服务器连接任务
    private class connectSessionScheduledService extends javafx.concurrent.ScheduledService<Number> {

        Number statu = 0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value.intValue() == 1) {
                        /**
                         * #CD0000 红色
                         * #7CCD7C 绿色
                         * #FFB90F 黄色
                         * #778899 灰色
                         */
                        leftstatus.setTextFill(Paint.valueOf("#7CCD7C"));
                        leftstatus.setText("已连接");
                        pf.cancelProgressBar();
                        connectSessionScheduledService.this.cancel();
                        //System.out.println("<--------------连接任务结束---------");
                    } else {
                        leftstatus.setTextFill(Paint.valueOf("#CD0000"));
                        leftstatus.setText("未连接");
                        connectSessionScheduledService.this.cancel();
                        pf.cancelProgressBar();
                    }
                }

                @Override
                protected void running() {
                    super.running();
                    System.out.println();
                    System.out.print("获取连接中...");
                    MI_getConedtion.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    if (statu.intValue() == 1) {
                        System.out.println("连接结束");
                    }
                    MI_getConedtion.setDisable(false);
                }

                @Override
                protected Number call() throws Exception {
                    //主要处理任务的地方
                    //System.out.println("-------------创建连接------------->");
                    GetConnectionSession gcs = new GetConnectionSession(serverInfo.getMyUseServerMap(), 0);
                    //创建执行服务
                    ExecutorService ser = Executors.newFixedThreadPool(Integer.parseInt(properties.getProperty("connectSessionScheduledService_FixedThreadPool")));
                    List<Future<Session>> resultList = new ArrayList<Future<Session>>();

                    statu = 1;
                    //创建线程执行
                    for (int i = 1; i <= serverInfo.getMyUseServerMap().size(); i++) {
                        try {
                            resultList.add(i - 1, ser.submit(gcs));
                        }catch (Exception e){
                            System.out.println(serverInfo.getMyUseServerMap().get(i-1)+"获取连接异常"+e.getMessage());
                        }
                    }
                    ser.shutdown();

//                    try {
//                        for (int i = 1; i <= serverInfo.getMyUseServerMap().size(); i++) {
//                            resultList.add(i - 1, ser.submit(gcs));
//                        }
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                        statu = -1;
//                        System.out.println("创建连接异常" + e.getMessage() + "请检查配置是否正确");
//                        ser.shutdownNow();
//                    } finally {
//                        ser.shutdown();
//                    }
                    for (Future<Session> fs : resultList) {
                        if(fs.get()!=null){
                            serverSessionMap.put(fs.get().getHost(), fs.get());
                        }else {
                            statu = -1;
                        }
                    }

                    return statu;
                }
            };
            return task;
        }
    }

    //断开服务器连接任务
    private class disConnectSessionScheduledService extends javafx.concurrent.ScheduledService<Number> {

        Number statu = 0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (statu.intValue() == 1) {
                        disConnectSessionScheduledService.this.cancel();
                        leftstatus.setTextFill(Paint.valueOf("#CD0000"));
                        leftstatus.setText("未连接");
                        System.out.println("已断开连接");
                        pf.cancelProgressBar();
                    }else {
                        pf.cancelProgressBar();
                        System.out.println("断开连接异常");
                        disConnectSessionScheduledService.this.cancel();
                        pf.cancelProgressBar();
                    }
                }

                @Override
                protected Number call() throws Exception {
                    //主要处理任务的地方
//                    Iterator it = serverInfo.getMyUseServerMap().keySet().iterator();
                    Iterator it = serverSessionMap.keySet().iterator();
                    //System.out.println("-------------断开连接------------->");
                    statu = 1;

                    //删除此段，断开连接时，就清除session就可以
                    while (it.hasNext()) {
                        String key = (String) it.next();
                        try {
                            //断开连接
                            serverSessionMap.get(key).disconnect();
                        } catch (Exception e) {
                            statu = -1;
                            System.out.println(key + " 断开连接异常：" + e.getMessage());
                        }
                        //System.out.println("----" + key + "---断开成功");
//            System.out.println("key:" + key);
//            System.out.println("value:" + serverMap.get(key)[1]);
                    }
                    //System.out.println("<------------------------------------");
                    serverSessionMap.clear();
                    return statu;
                }
            };
            return task;
        }
    }

    //开始监控任务，支持定时
    private class startJmonitorScheduledService extends ScheduledService<Number> {
        double count = 0.0;
        double progress = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            Task<Number> task = new Task<Number>() {

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value != null) {
                        if (value.intValue() < 0) {
                            L_processLabel.setText("");
                            B_startMonitor.setDisable(false);
                            count = 0.0;
                            progress = 0.0;
                            startJmonitorScheduledService.this.cancel();
                        } else {
                            Bar_process.setProgress(value.doubleValue());
                            if (value.intValue() >= 1) {
                                L_processLabel.setText("执行nmon完成");
                                //执行信息入库和表格展示
                                Date currentDate = new Date();
                                h2dbCRUDUtil.insertOrUpdateSql("INSERT INTO nmonMonitorList_table" +
                                "(startTime,frequency,duration,nmonName,PS,isDownload,isAnalysis,toLink)" +
                                " VALUES" +
                                "('"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentDate)+"','"+TF_frequency.getText()+"','"+TF_duration.getText()+"','"+TF_MonitoringNmonName.getText()+"','"+TF_PS.getText()+"','✖','✖','')" +
                                 "");
                                monitorHistoryDataList.add(new NmonMonitorListModel(String.valueOf(monitorHistoryDataList.size()+1),new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentDate),TF_frequency.getText(),TF_duration.getText(),TF_MonitoringNmonName.getText(),TF_PS.getText(),"✖","✖",""));

                                B_startMonitor.setDisable(false);
                                count = 0.0;
                                progress = 0.0;
                                startJmonitorScheduledService.this.cancel();
                            }
                        }
                    }
                }

                @Override
                protected void running() {
                    super.running();
                    B_startMonitor.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                }

                @Override
                protected Number call()  {
                    //主要处理任务的地方
                    //System.out.println("开始监控");
                    String user = "";// 用户名
                    String pwd = "";// 密码
                    String ip = "";// 服务器地址
                    String nmonpath = "";
                    String nmonbushulujing = TF_setNmonPath.getText();
                    String pinglv = TF_frequency.getText();
                    String cishu = TF_counts.getText();
                    String name = TF_MonitoringNmonName.getText();




                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        System.out.println("200延时异常");
                    }

                    //前置条件判断
                    if (leftstatus.getText().contains("未连接")) {
                        System.out.println("error :  请先连接相关服务器");
                        return -1;
                    } else if (TF_setNmonPath.getText().length() == 0) {
                        System.out.println("error :  请输入服务器监控部署路径!");
                        return -1;
                    } else if (pinglv.length() == 0 || cishu.length() == 0 || name.length() == 0) {
                        //判断是否存在空值
                        System.out.println("error :  必要参数存在空值!请检查测试频率、时长、监控名称是否完整！");
                        return -1;
                    } else {
                        Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
                        //printLogMessage("-------------开始监控------------>");
                        StartMonitor sm = new StartMonitor(serverInfo.getMyUseServerMap(), serverSessionMap, 0, nmonbushulujing, pinglv, cishu, name);
                        //创建执行服务
                        ExecutorService ser = Executors.newFixedThreadPool(Integer.parseInt(properties.getProperty("startJmonitorScheduledService_FixedThreadPool")));
                        List<Future<String>> resultList = new ArrayList<Future<String>>();
                        while (iterator.hasNext()) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            count++;
                            String[] values = (String[]) entry.getValue();
                            String key = (String) entry.getKey();
                            user = values[1];
                            ip = key;
                            pwd = values[2];
                            nmonpath = values[3];
                            //部署路径处理在执行时实现 StartMonitor 类

                            //System.out.print("ip:"+ip+"开始监控....");
                            //执行监控

                            resultList.add((int)count- 1, ser.submit(sm));

                             try {
                                 String str = resultList.get((int)count- 1).get();
                                 if (str.contains("此命名监控进程已存在")){
                                     System.out.println("执行.."+str+"执行中断，请修改名称后重新开始");
                                     return -1;
                                 }
//                                 else {
//                                     System.out.println(ip+"执行...执行结果："+str+"执行nmon成功");
//                                 }
                             } catch (InterruptedException e) {
                                 e.printStackTrace();
                                 System.out.println("开始监控异常1: "+e.getMessage());
                             } catch (ExecutionException e) {
                                 e.printStackTrace();
                                 System.out.println("开始监控异常2: "+e.getMessage());
                             }

                            //进度计算
                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }
                    }
                    return progress;
                }
            };
            return task;
        }
    }

    //停止监控任务
    private class stopJmonitorScheduledService extends ScheduledService<Number> {
        double count = 0.0;
        double progress = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            Task<Number> task = new Task<Number>() {

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value != null) {
                        if (value.intValue() < 0) {
                            L_processLabel.setText("");
                            B_stopMonitor.setDisable(false);
                            count = 0.0;
                            progress = 0.0;
                            stopJmonitorScheduledService.this.cancel();
                        } else {
                            Bar_process.setProgress(value.doubleValue());
                            if (value.intValue() >= 1) {
                                L_processLabel.setText("停止nmon完成");
                                B_stopMonitor.setDisable(false);
                                count = 0.0;
                                progress = 0.0;
                                stopJmonitorScheduledService.this.cancel();
                            }
                        }
                    }
                }

                @Override
                protected void running() {
                    super.running();
                    B_stopMonitor.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                }

                @Override
                protected Number call()  {
                    //主要处理任务的地方
                    //System.out.println("开始监控");
                    String user = "";// 用户名
                    String pwd = "";// 密码
                    String ip = "";// 服务器地址
                    String nmonpath = "";
                    String nmonbushulujing = TF_setNmonPath.getText();
                    String pinglv = TF_frequency.getText();
                    String cishu = TF_counts.getText();
                    String name = TF_MonitoringNmonName.getText();

                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        System.out.println("200延时异常");
                    }

                    //前置条件判断
                    if (leftstatus.getText().contains("未连接")) {
                        System.out.println("error :  请先连接相关服务器");
                        return -1;
                    } else if (TF_setNmonPath.getText().length() == 0) {
                        System.out.println("error :  请输入服务器监控部署路径!");
                        return -1;
                    } else {
                        Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
                        StopMonitor sm = new StopMonitor(serverInfo.getMyUseServerMap(), serverSessionMap, 0, nmonbushulujing, pinglv, cishu, name);
                        //创建执行服务
                        ExecutorService ser = Executors.newFixedThreadPool(Integer.parseInt(properties.getProperty("stopJmonitorScheduledService_FixedThreadPool")));
                        List<Future<String>> resultList = new ArrayList<Future<String>>();
                        while (iterator.hasNext()) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            count++;
                            String[] values = (String[]) entry.getValue();
                            String key = (String) entry.getKey();
                            user = values[1];
                            ip = key;
                            pwd = values[2];
                            nmonpath = values[3];
                            //部署路径处理在执行时实现 StartMonitor 类

                            //System.out.print("ip:"+ip+"开始监控....");
                            //执行监控
                            resultList.add((int)count- 1, ser.submit(sm));

                            try {
                                String str = resultList.get((int)count- 1).get();
                                if (str.contains("[error]")||str.contains("监控任务不存在")){
                                    System.out.println("执行结果: "+str+"...停止任务中断");
                                    return -1;
                                }
//                                else {
//                                    System.out.println(ip+"开始停止...执行结果："+str+"停止nmon成功");
//                                }
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                                System.out.println("停止监控异常1: "+e.getMessage());
                            } catch (ExecutionException e) {
                                e.printStackTrace();
                                System.out.println("停止监控异常2: "+e.getMessage());
                            }

                            //进度计算
                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }
                    }
                    return progress;
                }
            };
            return task;
        }
    }

    //到服务器删除指定nmon文件的任务
    private class deleteMonitorNmonFileService extends Service<Number> {
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void running() {
                    super.running();
                    L_processLabel.setText("nmon文件删除中..");
                    B_StartInstallNmon.setDisable(true);
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    B_StartInstallNmon.setDisable(false);
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value != null) {
                        if (value.intValue() < 0) {
                            L_processLabel.setText("");
                            B_deleteMonitorNmonFile.setDisable(false);
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            deleteMonitorNmonFileService.this.cancel();
                        } else {
                            Bar_process.setProgress(value.doubleValue());
                            if (value.intValue() == 1) {
                                L_processLabel.setText("删除完成");
                                B_deleteMonitorNmonFile.setDisable(false);
                                //初始化进度条
                                progress = 0.0;
                                count = 0.0;
                                deleteMonitorNmonFileService.this.cancel();
                            }
                        }
                    }
                }
                @Override
                protected Number call() {

                    String user = "";// 用户名
                    String pwd = "";// 密码
                    String ip = "";// 服务器地址
                    String nmonpath = "";
                    String nmonbushulujing = TF_setNmonPath.getText();
                    String name = TF_MonitoringNmonName.getText();

                    Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
                    //输入项不允许为空
                    double i = 1.0;
                    if (leftstatus.getText().contains("未连接")) {
                        System.out.println("error :  请先连接相关服务器");
                        return -1;
                    } else if (TF_setNmonPath.getText().length() == 0) {
                        System.out.println("error :  请输入服务器监控部署路径!");
                        return -1;
                    } else {
                        while (iterator.hasNext()) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            count++;
                            //用户3种情况
                            /**
                             * ~/myNmon 目录 普通用户  ~ 替换 /home/用户名/myNmon
                             * ~/myNmon 目录 root用户 ~ 替换 /用户名/myNmon
                             * /home/myNmon   不需要修改和替换
                             */
                            String[] values = (String[]) entry.getValue();
                            String key = (String) entry.getKey();
                            user = values[1];
                            ip = key;
                            pwd = values[2];
                            nmonpath = values[3];
//
                            //部署路径处理
                            if (nmonpath.toUpperCase().contains("DEFAULT") && TF_setNmonPath.getText().contains("~/")) {
                                if (user.toUpperCase().contains("ROOT")) {
                                    nmonbushulujing = TF_setNmonPath.getText().replace("~", "/" + user);
                                } else {
                                    nmonbushulujing = TF_setNmonPath.getText().replace("~", "/home/" + user);
                                }
                            } else {
                                nmonbushulujing = nmonpath.toString();
                            }
                            Session session = serverSessionMap.get(key.toString());
                            //System.out.println("session ip:"+session.getHost()+";session 状态:"+session.getClientVersion());

                            //开始部署
                            //判断部署路径是否存在
                            String result = null;
                            try {
                                result = execCommandByJSch(session, "if [ ! -d \"" + nmonbushulujing + "\" ];then echo 0;else echo 1;fi", "UTF-8");
                            } catch (IOException e) {
                                e.printStackTrace();
                                System.out.println(key+"1.获取内容异常");
                                return -1;
                            } catch (JSchException e) {
                                e.printStackTrace();
                                System.out.println(key+"2连接异常");
                                return -1;
                            }

                            if (result.contains("0")) {
                                System.out.println(key.toString() + " 部署监控文件夹不存在");
                                return -1;
                            } else {
                                //开始删除文件，判断系统为linux aix 或 unix
                                try {
                                    if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
                                        execCommandByJSch(session, "rm -f " + nmonbushulujing + File.separator + ip + "_" + name + ".nmon", "UTF-8");
                                    } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
                                        execCommandByJSch(session, "rm -f " + nmonbushulujing + File.separator + ip + "_" + name + ".nmon", "UTF-8");
                                    } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
                                        execCommandByJSch(session, "rm -f " + nmonbushulujing + File.separator + ip + "_" + name + ".nmon", "UTF-8");
                                    }
                                }catch (Exception e){
                                    e.printStackTrace();
                                    System.out.println("删除监控文件异常");
                                }
                            }

                            //进度计算
                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }
                    }
                    return null;
                }


//                @Override
//                protected Number call() throws Exception {
//                    String user = "";// 用户名
//                    String ip = "";// 服务器地址
//                    String nmonpath = "";
//                    String name = TF_MonitoringNmonName.getText();
//                    String nmonbushulujing = TF_setNmonPath.getText();
//                    Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
//                    //输入项不允许为空
//                    double i = 1.0;
//                    if (leftstatus.getText().contains("未连接")) {
//                        System.out.println("error :  请先连接相关服务器");
//                        return -1;
//                    } else if (TF_setNmonPath.getText().length() == 0) {
//                        System.out.println("error :  请输入服务器监控部署路径!");
//                        return -1;
//                    } else {
//                        while (iterator.hasNext()) {
//                            Map.Entry entry = (Map.Entry) iterator.next();
//                            //用户3种情况
//                            /**
//                             * ~/myNmon 目录 普通用户  ~ 替换 /home/用户名/myNmon
//                             * ~/myNmon 目录 root用户 ~ 替换 /用户名/myNmon
//                             * /home/myNmon   不需要修改和替换
//                             */
//                            String[] values = (String[]) entry.getValue();
//                            String key = (String) entry.getKey();
//                            user = values[1];
//                            ip = key;
//                            nmonpath = values[3];
//
//                            //部署路径处理
//                            if (nmonpath.toUpperCase().contains("DEFAULT") && nmonbushulujing.contains("~/")) {
//                                if (user.toUpperCase().contains("ROOT")) {
//                                    nmonbushulujing = nmonbushulujing.replace("~", "/" + user);
//                                } else {
//                                    nmonbushulujing = nmonbushulujing.replace("~", "/home/" + user);
//                                }
//                            } else {
//                                nmonbushulujing = nmonpath.toString();
//                            }
//                            Session session = serverSessionMap.get(key.toString());
//                            //判断部署路径是否存在
//                            String result = execCommandByJSch(session, "if [ ! -d \"" + nmonbushulujing + "\" ];then echo 0;else echo 1;fi", "UTF-8");
//                            if (result.contains("0")) {
//                                System.out.println(key.toString() + "部署监控文件夹myNmon不存在");
//                            } else {
//                                //开始删除文件，判断系统为linux aix 或 unix
//                                if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
//                                    execCommandByJSch(session, "rm -f " + nmonbushulujing + File.separator + ip + "_" + name + ".nmon", "UTF-8");
//                                } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
//                                    execCommandByJSch(session, "rm -f " + nmonbushulujing + File.separator + ip + "_" + name + ".nmon", "UTF-8");
//                                } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
//                                    execCommandByJSch(session, "rm -f " + nmonbushulujing + File.separator + ip + "_" + name + ".nmon", "UTF-8");
//                                }
//                            }
//                            i=i+1;
//                            //计算返回进度
//                            progress = i / serverInfo.getMyUseServerMap().size();
//                            return progress;
//                        }
//
//                    }
//                    return null;
//                }
            };
            return task;
        }
    }

    //到服务器下载指定nmon文件的任务
    private class downloadMonitorNmonFileService extends Service<Number> {
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void running() {
                    super.running();
                    L_processLabel.setText("nmon文件下载中..");
                    B_StartInstallNmon.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    B_StartInstallNmon.setDisable(false);
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    B_StartInstallNmon.setDisable(false);
                }

                @Override
                protected void failed() {
                    super.failed();
                    B_StartInstallNmon.setDisable(false);
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value != null) {
                        if (value.intValue() < 0) {
                            L_processLabel.setText("");
                            B_startDownload.setDisable(false);
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            downloadMonitorNmonFileService.this.cancel();
                        } else {
                            Bar_process.setProgress(value.doubleValue());
                            if (value.intValue() == 1) {
                                L_processLabel.setText("下载完成");
                                //更新下载信息入库和表格展示
                                Date currentDate = new Date();
                                h2dbCRUDUtil.insertOrUpdateSql("UPDATE nmonMonitorList_table SET isDownload = '✓' WHERE nmonName like '%"+TF_downloadFileName.getText().replace("*.nmon","").replace("*","")+"%'");
                                ResultSet resultSet = h2dbCRUDUtil.selectSql("Select id from nmonMonitorList_table where nmonName like '%"+TF_downloadFileName.getText().replace("*.nmon","").replace("*","")+"%'");
                                try {
                                    while (resultSet.next()){
//                                        System.out.println(resultSet.getInt("id"));
                                        monitorHistoryDataList.get(resultSet.getInt("id")-1).setIsDownload("✓");
                                    }
                                }catch (Exception e){
                                    e.printStackTrace();
                                    System.out.println(e.getMessage());
                                }

                                //monitorHistoryDataList.add(new NmonMonitorListModel(monitorHistoryDataList.size()+1+"",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentDate),TF_frequency.getText(),TF_duration.getText(),TF_MonitoringNmonName.getText(),TF_PS.getText(),"false","false",""));

                                B_startDownload.setDisable(false);
                                //初始化进度条
                                progress = 0.0;
                                count = 0.0;
                                downloadMonitorNmonFileService.this.cancel();
                            }
                        }
                    }
                }
                @Override
                protected Number call() {

                    String user = "";// 用户名
                    String pwd = "";// 密码
                    String ip = "";// 服务器地址
                    int port = 22;// 端口号
                    String nmonpath = "";
                    String nmonbushulujing = TF_setNmonPath.getText();
                    String name = TF_MonitoringNmonName.getText();
                    String wenjianming = TF_downloadFileName.getText();
                    String cunfangdizhi = TF_downloadPath.getText()+File.separator+TF_downloadPath1.getText();

                    Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
                    //输入项不允许为空
                    double i = 1.0;
                    if (leftstatus.getText().contains("未连接")) {
                        System.out.println("error :  请先连接相关服务器");
                        return -1;
                    } else if (TF_setNmonPath.getText().length() == 0) {
                        System.out.println("error :  请输入服务器监控部署路径!");
                        return -1;
                    } else {
                        while (iterator.hasNext()) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            count++;
                            //用户3种情况
                            /**
                             * ~/myNmon 目录 普通用户  ~ 替换 /home/用户名/myNmon
                             * ~/myNmon 目录 root用户 ~ 替换 /用户名/myNmon
                             * /home/myNmon   不需要修改和替换
                             */
                            String[] values = (String[]) entry.getValue();
                            String key = (String) entry.getKey();
                            user = values[1];
                            ip = key;
                            pwd = values[2];
                            nmonpath = values[3];
//
                            //部署路径处理
                            if (nmonpath.toUpperCase().contains("DEFAULT") && TF_setNmonPath.getText().contains("~/")) {
                                if (user.toUpperCase().contains("ROOT")) {
                                    nmonbushulujing = TF_setNmonPath.getText().replace("~", "/" + user);
                                } else {
                                    nmonbushulujing = TF_setNmonPath.getText().replace("~", "/home/" + user);
                                }
                            } else {
                                nmonbushulujing = nmonpath.toString();
                            }
                            Session session = serverSessionMap.get(key.toString());
                            SFTPUtil sftp = new SFTPUtil(ip, port, user, pwd);
                            try {
                                sftp.connect();
                            } catch (Exception e) {
                                e.printStackTrace();
                                System.out.println("[ "+ip+" ]下载时连接异常:"+e.getMessage());
                            }
                            //System.out.println("session ip:"+session.getHost()+";session 状态:"+session.getClientVersion());

                            //开始部署
                            //判断部署路径是否存在
                            String result = null;
                            try {
                                result = execCommandByJSch(session, "if [ ! -d \"" + nmonbushulujing + "\" ];then echo 0;else echo 1;fi", "UTF-8");
                            } catch (IOException e) {
                                e.printStackTrace();
                                System.out.println(key+"1.获取内容异常");
                                return -1;
                            } catch (JSchException e) {
                                e.printStackTrace();
                                System.out.println(key+"2连接异常");
                                return -1;
                            }

                            if (result.contains("0")) {
                                System.out.println(key.toString() + " 部署监控文件夹不存在");
                                return -1;
                            } else {
                                try {
                                //开始下载文件，判断系统为linux aix 或 unix
                                    if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
                                        sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
                                    } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
                                        sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
                                    } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
                                        sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
                                    }
                                    //System.out.println("[ "+ip+" ]下载成功");
                                }catch (Exception e){
                                    e.printStackTrace();
                                    System.out.println("下载监控文件异常"+e.getMessage());
                                }
                            }

                            //进度计算
                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }
                    }
                    return null;
                }

//                @Override
//                protected Number call() throws Exception {
//                    String user = "";// 用户名
//                    String ip = "";// 服务器地址
//                    String pwd = "";// 密码
//                    String nmonpath = "";
//                    int port = 22;// 端口号
//                    int timeout = 10000000;
//                    String wenjianming = TF_downloadFileName.getText();
//                    String nmonbushulujing = TF_setNmonPath.getText();
//                    String cunfangdizhi = TF_downloadPath.getText();
//                    Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
//                    //输入项不允许为空
//                    double i = 1.0;
//                    if (leftstatus.getText().contains("未连接")) {
//                        System.out.println("error :  请先连接相关服务器");
//                        return -1;
//                    } else if (TF_setNmonPath.getText().length() == 0) {
//                        System.out.println("error :  请输入服务器监控部署路径!");
//                        return -1;
//                    } else {
//                        while (iterator.hasNext()) {
//                            Map.Entry entry = (Map.Entry) iterator.next();
//                            //用户3种情况
//                            /**
//                             * ~/myNmon 目录 普通用户  ~ 替换 /home/用户名/myNmon
//                             * ~/myNmon 目录 root用户 ~ 替换 /用户名/myNmon
//                             * /home/myNmon   不需要修改和替换
//                             */
//                            String[] values = (String[]) entry.getValue();
//                            String key = (String) entry.getKey();
//                            user = values[1];
//                            pwd = values[2];
//                            ip = key;
//                            nmonpath = values[3];
//
//                            //部署路径处理
//                            if (nmonpath.toUpperCase().contains("DEFAULT") && nmonbushulujing.contains("~/")) {
//                                if (user.toUpperCase().contains("ROOT")) {
//                                    nmonbushulujing = nmonbushulujing.replace("~", "/" + user);
//                                } else {
//                                    nmonbushulujing = nmonbushulujing.replace("~", "/home/" + user);
//                                }
//                            } else {
//                                nmonbushulujing = nmonpath.toString();
//                            }
//                            Session session = serverSessionMap.get(key.toString());
//                            SFTPUtil sftp = new SFTPUtil(ip, port, user, pwd);
//                            sftp.connect();
//                            //判断部署路径是否存在
//                            String result = execCommandByJSch(session, "if [ ! -d \"" + nmonbushulujing + "\" ];then echo 0;else echo 1;fi", "UTF-8");
//                            if (result.contains("0")) {
//                                System.out.println(key.toString() + "部署监控文件夹myNmon不存在");
//                            } else {
//                                //开始删除文件，判断系统为linux aix 或 unix
//                                if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
//                                    sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
//                                } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
//                                    sftp.downloadFile(nmonbushulujing, wenjianming, "/Users/wutongchun/IdeaProjects/javaFX/javaFX_ToolsSummary/download");
//                                } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
//                                    sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
//                                }
//                            }
//                            i=i+1;
//                            //计算返回进度
//                            progress = i / serverInfo.getMyUseServerMap().size();
//                            return progress;
//                        }
//
//                    }
//                    return null;
//                }
            };
            return task;
        }
    }

    //到服务器下载指定nmon文件的任务
    private class ZDYdownloadFileService extends Service<Number> {
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void running() {
                    super.running();
                    L_processLabel.setText("文件下载中..");
                    B_ZDYdownload.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    B_ZDYdownload.setDisable(false);
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    B_ZDYdownload.setDisable(false);
                }

                @Override
                protected void failed() {
                    super.failed();
                    B_ZDYdownload.setDisable(false);
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);
                    if (value != null) {
                        if (value.intValue() < 0) {
                            L_processLabel.setText("");
                            B_ZDYdownload.setDisable(false);
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            ZDYdownloadFileService.this.cancel();
                        } else {
                            Bar_process.setProgress(value.doubleValue());
                            if (value.intValue() == 1) {
                                L_processLabel.setText("下载完成");
                                System.out.println("下载完成");
                                B_ZDYdownload.setDisable(false);
                                //初始化进度条
                                progress = 0.0;
                                count = 0.0;
                                ZDYdownloadFileService.this.cancel();
                            }
                        }
                    }
                }
                @Override
                protected Number call() {

                    String user = "";// 用户名
                    String pwd = "";// 密码
                    String ip = "";// 服务器地址
                    int port = 22;// 端口号
                    String nmonpath = "";
                    String nmonbushulujing = TF_ServiceAbsolutePath.getText();
                    String wenjianming = TF_FileName.getText();
                    String cunfangdizhi = TF_FileAbsolutePath.getText()+File.separator;

                    Iterator iterator = serverInfo.getMyUseServerMap().entrySet().iterator();
                    //输入项不允许为空
                    double i = 1.0;
                    if (leftstatus.getText().contains("未连接")) {
                        System.out.println("error :  请先连接相关服务器");
                        return -1;
                    } else if (TF_setNmonPath.getText().length() == 0) {
                        System.out.println("error :  请输入服务器监控部署路径!");
                        return -1;
                    } else {
                        while (iterator.hasNext()) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            count++;
                            //用户3种情况
                            /**
                             * ~/myNmon 目录 普通用户  ~ 替换 /home/用户名/myNmon
                             * ~/myNmon 目录 root用户 ~ 替换 /用户名/myNmon
                             * /home/myNmon   不需要修改和替换
                             */
                            String[] values = (String[]) entry.getValue();
                            String key = (String) entry.getKey();
                            user = values[1];
                            ip = key;
                            pwd = values[2];
                            Session session = serverSessionMap.get(key.toString());
                            SFTPUtil sftp = new SFTPUtil(ip, port, user, pwd);
                            try {
                                sftp.connect();
                            } catch (Exception e) {
                                e.printStackTrace();
                                System.out.println("[ "+ip+" ]下载时连接异常:"+e.getMessage());
                            }
                            //System.out.println("session ip:"+session.getHost()+";session 状态:"+session.getClientVersion());

                            //开始部署
                            //判断部署路径是否存在
                            String result = null;
                            try {
                                result = execCommandByJSch(session, "if [ ! -d \"" + nmonbushulujing + "\" ];then echo 0;else echo 1;fi", "UTF-8");
                            } catch (IOException e) {
                                e.printStackTrace();
                                System.out.println(key+"1.获取内容异常");
                                return -1;
                            } catch (JSchException e) {
                                e.printStackTrace();
                                System.out.println(key+"2连接异常");
                                return -1;
                            }

                            if (result.contains("0")) {
                                System.out.println(key.toString() + " 服务器文件夹不存在");
                                return -1;
                            } else {
                                try {
                                    //开始下载文件，判断系统为linux aix 或 unix
                                    if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("UNIX")) {
                                        sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
                                    } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("LINUX")) {
                                        sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
                                    } else if (execCommandByJSch(session, "uname", "UTF-8").toUpperCase().contains("AIX")) {
                                        sftp.downloadFile(nmonbushulujing, wenjianming, cunfangdizhi);
                                    }
                                    //System.out.println("[ "+ip+" ]下载成功");
                                }catch (Exception e){
                                    e.printStackTrace();
                                    System.out.println("下载文件异常"+e.getMessage());
                                }
                            }

                            //进度计算
                            progress = count/serverInfo.getMyUseServerMap().size();
                            //System.out.println("progress:"+progress);

                            if(progress==1){
                                return progress;
                            }else {
                                updateValue((Number) progress);
                            }
                        }
                    }
                    return null;
                }

            };
            return task;
        }
    }


    //刷新delaytime 时间
//    private class delaytimeService extends ScheduledService<Number[]> {
//        double progress = 0.0;
//        double count = 0.0;
//        Number nu[] = new Number[2];
//        @Override
//        protected javafx.concurrent.Task<Number[]> createTask() {
//            javafx.concurrent.Task<Number[]> task = new javafx.concurrent.Task<Number[]>() {
//                @Override
//                protected void running() {
//                    super.running();
//                    B_startMonitor.setDisable(true);
//                    B_stopMonitor.setDisable(true);
//
//                }
//
//                @Override
//                protected void updateMessage(String message) {
//                    super.updateMessage(message);
////                    System.out.println(message);
////                    L_delayTime.setText("倒计时 "+message+"s");
//                }
//
//                @Override
//                protected void updateValue(Number[] value) {
//                    super.updateValue(value);
////                    System.out.println(Thread.currentThread().getName());
//
//                    if (value != null) {
//                        if (value[0].intValue() < 0) {
//                            B_startMonitor.setDisable(false);
//                            B_stopMonitor.setDisable(false);
//                            //初始化进度条
//                            progress = 0.0;
//                            count = 0.0;
//                            delaytimeService.this.cancel();
//                        } else {
//                            L_delayTime.setText("倒计时 "+value[1].toString()+"s");
//                            Bar_process.setProgress(value[0].doubleValue());
//                            //System.out.println("倒计时 "+value[1]+"s");
//                            //L_processLabel.setText("jlskdjfl");
//                            if (value[0].intValue() == 1) {
//                                L_processLabel.setText("倒计时完成");
//                                L_delayTime.setText("");
//                                B_startMonitor.setDisable(false);
//                                B_stopMonitor.setDisable(false);
//                                //初始化进度条
//                                progress = 0.0;
//                                count = 0.0;
//                                delaytimeService.this.cancel();
//                            }
//                        }
//                    }
//                }
//
//                @Override
//                protected Number[] call() {
//                    //System.out.println("执行任务");
//                    int delaytime = Integer.parseInt(TF_delayed_h.getText())*60*60+Integer.parseInt(TF_delayed_min.getText())*60;
//                    double delaytimefinal=(double) delaytime;
//                    //执行任务的地方
//                    while (delaytime>0){
//                        delaytime--;
//                        nu[1]=delaytime;
//                        count++;
//                        try {
//                            Thread.sleep(1000);
//                        } catch (InterruptedException e) {
//                            e.printStackTrace();
//                        }
//                        //进度计算
//                        progress = count/delaytimefinal;
//                        nu[0]=progress;
//
//                        if(progress==1){
//                            return nu;
//                        }else {
//                            updateValue(nu);
//                        }
//                    }
//                    return null;
//                }
//            };
//            return task;
//        }
//    }
    private class delaytimeService extends ScheduledService<Number> {
        double progress = 0.0;
        double count = 0.0;
        Number nu[] = new Number[2];
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {
                @Override
                protected void running() {
                    super.running();
                    B_startMonitor.setDisable(true);
                    B_stopMonitor.setDisable(true);
                }

                @Override
                protected void updateMessage(String message) {
                    super.updateMessage(message);
//                    System.out.println(message);
//                    L_delayTime.setText("倒计时 "+message+"s");
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                     progress = 0.0;
                     count = 0.0;
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);

                    if (value != null) {
                        if(!delayFlag){
                            delaytimeService.this.cancel();
                        }
                        if (value.intValue() < 0) {
                            B_startMonitor.setDisable(false);
                            B_stopMonitor.setDisable(false);
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            delaytimeService.this.cancel();
                        } else {
                            Bar_process.setProgress(value.doubleValue());
                            //System.out.println("倒计时 "+value[1]+"s");
                            //L_processLabel.setText("jlskdjfl");
                            if (value.intValue() == 1) {
                                L_processLabel.setText("倒计时完成");
                                L_delayTime.setText("");
                                B_startMonitor.setDisable(false);
                                B_stopMonitor.setDisable(false);
                                L_nodelay.setText("");
                                delayFlag=false;
                                //初始化进度条
                                progress = 0.0;
                                count = 0.0;
                                delaytimeService.this.cancel();
                            }
                        }
                    }
                }

                @Override
                protected Number call() {
                    //System.out.println("执行任务");
                    int delaytime = Integer.parseInt(TF_delayed_h.getText())*60*60+Integer.parseInt(TF_delayed_min.getText())*60;
                    double delaytimefinal=(double) delaytime;
                    //执行任务的地方
                    while (delaytime>0){
                        delaytime--;
                        nu[1]=delaytime;
                        count++;
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            //System.err.println(e.getMessage());
                        }
                        //进度计算
                        progress = count/delaytimefinal;
                        nu[0]=progress;

                        if(progress==1){
                            return progress;
                        }else {
                            updateValue((Number) progress);
                            this.updateMessage(""+delaytime);
                        }
                    }
                    return null;
                }
            };
            return task;
        }
    }


    //解析nmon结果
    private class analysisNmonResultService extends Service<Number> {
        double progress = 0.0;
        double count = 0.0;
        @Override
        protected javafx.concurrent.Task<Number> createTask() {
            javafx.concurrent.Task<Number> task = new javafx.concurrent.Task<Number>() {

                @Override
                protected void running() {
                    super.running();
                    L_processLabel.setText("nmon解析中..");
                    B_AnalyseNmonResult.setDisable(true);
                }

                @Override
                protected void succeeded() {
                    super.succeeded();
                    B_AnalyseNmonResult.setDisable(false);
                }

                @Override
                protected void cancelled() {
                    super.cancelled();
                    B_AnalyseNmonResult.setDisable(false);
                }

                @Override
                protected void failed() {
                    super.failed();
                    B_AnalyseNmonResult.setDisable(false);
                }

                @Override
                protected void updateValue(Number value) {
                    super.updateValue(value);

                    if (value.intValue() < 0) {
                        L_processLabel.setText("");
                        B_AnalyseNmonResult.setDisable(false);
                        //初始化进度条
                        progress = 0.0;
                        count = 0.0;
                        analysisNmonResultService.this.cancel();
                    } else {
                        Bar_process.setProgress(value.doubleValue());
                        if (value.intValue() >= 1) {
                            L_processLabel.setText("解析完成");
                            B_AnalyseNmonResult.setDisable(false);
                            //初始化进度条
                            progress = 0.0;
                            count = 0.0;
                            analysisNmonResultService.this.cancel();

                            //更新解析信息入库和表格展示
                            Date currentDate = new Date();
                            h2dbCRUDUtil.insertOrUpdateSql("UPDATE nmonMonitorList_table SET isAnalysis = '✓' WHERE nmonName like '%"+TF_downloadFileName.getText().replace("*.nmon","").replace("*","")+"%'");
                            ResultSet resultSet = h2dbCRUDUtil.selectSql("Select id from nmonMonitorList_table where nmonName like '%"+TF_downloadFileName.getText().replace("*.nmon","").replace("*","")+"%'");
                            try {
                                while (resultSet.next()){
//                                        System.out.println(resultSet.getInt("id"));
                                    monitorHistoryDataList.get(resultSet.getInt("id")-1).setIsAnalysis("✓");
                                }
                            }catch (Exception e){
                                e.printStackTrace();
                                System.out.println(e.getMessage());
                            }

                            sample.analysis.controller.MyController.ANALYSIS_UI_reoportFilePath=TF_downloadPath1.getText();




//                            //解析完成，打开窗口展示
//                            File file = new File("conf"+File.separator+"javaFX_NmonAnalysisTools.fxml");
////        //System.out.println(file.toURI().toURL());
//                            try {
//                                Parent target = FXMLLoader.load(file.toURI().toURL());
//                                Scene scene = new Scene(target, 1150, 600); //创建场景；
//                                Stage stg=new Stage();//创建舞台；
//                                stg.setTitle("NmonAnalysisTools");
//                                //设置页面长、宽、高
//                                stg.setScene(scene); //将场景载入舞台；
//                                stg.show(); //显示窗口；
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                            }
                            //修改为调用本地浏览器打开解析结果
                            File htmlfile = new File("dist"+File.separator+"index.html");
                            if (java.awt.Desktop.isDesktopSupported()) {
                                try {
                                    // 创建一个URI实例
                                    java.net.URI uri = java.net.URI.create("file://"+htmlfile.getAbsolutePath());
                                    // 获取当前系统桌面扩展
                                    java.awt.Desktop dp = java.awt.Desktop.getDesktop();
                                    // 判断系统桌面是否支持要执行的功能
                                    if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
                                        // 获取系统默认浏览器打开链接
                                        dp.browse(uri);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }

                        }
                    }

                }
                @Override
                protected Number call() {

                    //获取nmon,然后解析

                    //输入项不允许为空
                    //
                    //判断文件夹是否存在
                    File folder = new File(TF_downloadPath.getText() + File.separator + TF_downloadPath1.getText());
                    NmonUtil nmonUtil = new NmonUtil();
                    String[] nmonName = nmonUtil.getNmonName(TF_downloadPath.getText() + File.separator + TF_downloadPath1.getText());
                    if (!folder.exists() && !folder.isDirectory()) {
                        System.out.println("[ " + TF_downloadPath.getText() + File.separator + TF_downloadPath1.getText() + " ] 文件夹不存在或非文件夹");
                    } else {
                        //判断文件夹中nmon文件是否存在
                        if (nmonName.length > 0) {
                            try {
                                nmonUtil.writeAnalysisResultToJson(nmonName, TF_downloadPath.getText() + File.separator + TF_downloadPath1.getText(), TF_downloadPath1.getText() + ".json");
                                Thread.sleep(1000);

                                return 1;
                            } catch (Exception e) {
                                System.out.println("生成解析结果文件异常");
                                return -1;
                            }
                        }
                        return null;
                    }
                    return 1;
                }

            };
            return task;
        }
    }

    private class test extends ScheduledService<Number>{
        int i = 5;

        @Override
        protected Task<Number> createTask() {
            Task task = new Task() {
                @Override
                protected void updateValue(Object value) {
                    super.updateValue(value);
                    L_delayTime.setText(value.toString());
                    if((int)value<0){
                        L_delayTime.setText("");
                        test.this.cancel();
                    }
                }

                @Override
                protected Object call() throws Exception {

                    System.out.println("i"+i);
                    //Thread.sleep(1000);
                    i--;
                    return i;
                }
            };
            return task;
        }
    }

    public  void updataTolink(String reportPath){

    }



}
